結果

問題 No.2751 429-like Number
ユーザー AerenAeren
提出日時 2024-05-10 21:37:47
言語 C++23
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 140 ms / 4,000 ms
コード長 2,033 bytes
コンパイル時間 3,442 ms
コンパイル使用メモリ 254,132 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-05-10 21:38:16
合計ジャッジ時間 5,100 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 2 ms
6,944 KB
testcase_07 AC 25 ms
6,944 KB
testcase_08 AC 28 ms
6,944 KB
testcase_09 AC 22 ms
6,940 KB
testcase_10 AC 39 ms
6,944 KB
testcase_11 AC 71 ms
6,940 KB
testcase_12 AC 71 ms
6,940 KB
testcase_13 AC 65 ms
6,940 KB
testcase_14 AC 92 ms
6,940 KB
testcase_15 AC 140 ms
6,940 KB
testcase_16 AC 45 ms
6,944 KB
testcase_17 AC 45 ms
6,944 KB
testcase_18 AC 68 ms
6,944 KB
testcase_19 AC 68 ms
6,944 KB
testcase_20 AC 68 ms
6,940 KB
testcase_21 AC 67 ms
6,944 KB
testcase_22 AC 68 ms
6,940 KB
testcase_23 AC 68 ms
6,944 KB
testcase_24 AC 70 ms
6,940 KB
testcase_25 AC 67 ms
6,944 KB
testcase_26 AC 68 ms
6,940 KB
testcase_27 AC 67 ms
6,940 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// #pragma GCC optimize("O3,unroll-loops")
#include <bits/stdc++.h>
// #include <x86intrin.h>
using namespace std;
#if __cplusplus >= 202002L
using namespace numbers;
#endif

// Correctness proved in https://github.com/kth-competitive-programming/kactl/blob/master/doc/modmul-proof.pdf
// twice faster than (__int128_t)a * b % M
using ull = unsigned long long;
ull mod_mul(ull a, ull b, ull M){
	long long res = a * b - M * ull(1.L / M * a * b);
	return res + M * (res < 0) - M * (res >= (long long)M);
}
ull mod_pow(ull b, ull e, ull mod){
	ull res = 1;
	for(; e; b = mod_mul(b, b, mod), e >>= 1) if(e & 1) res = mod_mul(res, b, mod);
	return res;
}
// Millar Rabin Primality Test
// 7 times slower than a^b mod c
bool isprime(ull n){
	if(n < 2 || n % 6 % 4 != 1) return (n | 1) == 3;
	ull s = __builtin_ctzll(n - 1), d = n >> s;
	for(ull a: {2, 325, 9375, 28178, 450775, 9780504, 1795265022}){
		ull p = mod_pow(a, d, n), i = s;
		while(p != 1 && p != n - 1 && a % n && i --) p = mod_mul(p, p, n);
		if(p != n - 1 && i != s) return false;
	}
	return true;
}
// Pollard rho algorithm
// O(n^1/4)
ull get_factor(ull n){
	auto f = [n](ull x){ return mod_mul(x, x, n) + 1; };
	ull x = 0, y = 0, t = 30, prd = 2, i = 1, q;
	while(t ++ % 40 || gcd(prd, n) == 1){
		if(x == y) x = ++ i, y = f(x);
		if(q = mod_mul(prd, max(x, y) - min(x, y), n)) prd = q;
		x = f(x), y = f(f(y));
	}
	return gcd(prd, n);
}
// Returns the prime factors in arbitrary order
vector<ull> factorize(ull n){
	if(n == 1) return {};
	if(isprime(n)) return {n};
	ull x = get_factor(n);
	auto l = factorize(x), r = factorize(n / x);
	l.insert(l.end(), r.begin(), r.end());
	return l;
}

int main(){
	cin.tie(0)->sync_with_stdio(0);
	cin.exceptions(ios::badbit | ios::failbit);
	auto __solve_tc = [&](auto __tc_num)->int{
		long long x;
		cin >> x;
		factorize(x).size() == 3 ? cout << "Yes\n" : cout << "No\n";
		return 0;
	};
	int __tc_cnt;
	cin >> __tc_cnt;
	for(auto __tc_num = 0; __tc_num < __tc_cnt; ++ __tc_num){
		__solve_tc(__tc_num);
	}
	return 0;
}

/*

*/
0