绝望 & 求卡常
查看原帖
绝望 & 求卡常
362750
TernaryTree楼主2022/4/27 17:41
#include <bits/stdc++.h>

using namespace std;

const int maxn = 3e7 + 1;

namespace FastIO
{
    struct instream
    {
        int base = 10;

        friend instream &operator>>(instream &in, int &num)
        {
            int flag = 1;
            int ans = 0;
            char ch = getchar();
            while (ch < '0' || ch > '9')
            {
                if (ch == '-')
                {
                    flag = -flag;
                }
                ch = getchar();
            }

            while (ch >= '0' && ch <= '9')
            {
                ans = ans * in.base + (ch - '0');
                ch = getchar();
            }
            num = ans * flag;
            return in;
        }
    };

    struct outstream
    {
        template<typename _CharT, typename _Traits = char_traits<_CharT>>
        struct typ {
            typedef basic_ostream<_CharT, _Traits>& (* end) (basic_ostream<_CharT, _Traits>&);
        };

        int base = 10;

        friend outstream &operator<<(outstream &out, int num)
        {
            if (num < 0)
            {
                putchar('-');
                num = -num;
            }
            if (num >= 10)
            {
                out << num / 10;
            }
            putchar(num % 10 + '0');
            return out;
        }

        friend outstream &operator<<(outstream &out, const char * s) {
            printf("%s", s);
            return out;
        }

        friend outstream &operator<<(outstream &out, string s) {
            cout << s;
            return out;
        }

        friend outstream &operator<<(outstream &out, typ<char>::end e) {
            puts("");
            return out;
        }
    };

    instream fin;
    outstream fout;
}

namespace init {
	int prime[maxn];
	bool book[maxn];
	int fac[maxn];
	int cnt;
	
	void sieve() {
		book[0] = book[1] = 1;
		for (register int i = 1; i < maxn; ++i) {
			if (!book[i]) {
				prime[++cnt] = i;
				fac[i] = i;
			}
			for (register int j = 1; j <= cnt && prime[j] * i < maxn; ++j) {
				fac[prime[j] * i] = prime[j];
				book[prime[j] * i] = 1;
			}
		}
	}
};

namespace mainloop {
	int t, n, k;
	
	void testcase() {
		using namespace init;
		using namespace FastIO;
		fin >> n >> k;
		if (k % 3 != 0) {
			fout << -1 << endl;
		} else if (n % 2 == 1) {
			if (fac[n] == 3) {
				fout << 0 << endl;
			} else {
				int tm2 = (int) (log2((fac[n] + 1) & (- fac[n] - 1)) + 1e-6);
				fout << (tm2 <= 2 ? 1 : tm2 - 1) << endl;
			}
		} else {
			int tm2 = (int) (log2(n & (-n)) + 1e-6);
			fout << (tm2 <= 2 ? 0 : tm2 - 2) << endl;
		}
	}
	
	void start() {
		cin >> t;
		while (t--) {
			testcase();
		}
	}
};

int main() {
	init::sieve();
	mainloop::start();
	return 0; 
}

提交记录

就差那一点啊..

求神仙帮忙卡常。

2022/4/27 17:41
加载中...