結果
| 問題 |
No.2750 Number of Prime Factors
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-05-10 21:33:17 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 3 ms / 2,000 ms |
| コード長 | 2,559 bytes |
| コンパイル時間 | 3,027 ms |
| コンパイル使用メモリ | 248,364 KB |
| 実行使用メモリ | 6,820 KB |
| 最終ジャッジ日時 | 2024-12-20 04:29:06 |
| 合計ジャッジ時間 | 3,864 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 19 |
ソースコード
// #pragma GCC optimize("O3,unroll-loops")
#include <bits/stdc++.h>
// #include <x86intrin.h>
using namespace std;
#if __cplusplus >= 202002L
using namespace numbers;
#endif
struct number_theory{
int SZ;
vector<int> lpf, prime;
number_theory(int SZ): SZ(SZ), lpf(SZ + 1){ // O(SZ)
lpf[0] = lpf[1] = numeric_limits<int>::max() / 2;
for(auto i = 2; i <= SZ; ++ i){
if(!lpf[i]) lpf[i] = i, prime.push_back(i);
for(auto j = 0; j < (int)prime.size() && prime[j] <= lpf[i] && prime[j] * i <= SZ; ++ j) lpf[prime[j] * i] = prime[j];
}
}
vector<int> precalc_mobius() const{
vector<int> mobius(SZ + 1, 1);
for(auto i = 2; i <= SZ; ++ i){
if(i / lpf[i] % lpf[i]) mobius[i] = -mobius[i / lpf[i]];
else mobius[i] = 0;
}
return mobius;
}
vector<int> precalc_phi() const{
vector<int> phi(SZ + 1, 1);
for(auto i = 2; i <= SZ; ++ i){
if(i / lpf[i] % lpf[i]) phi[i] = phi[i / lpf[i]] * (lpf[i] - 1);
else phi[i] = phi[i / lpf[i]] * lpf[i];
}
return phi;
}
// Returns {gcd(0, n), ..., gcd(SZ, n)}
vector<int> precalc_gcd(int n) const{
vector<int> res(SZ + 1, 1);
res[0] = n;
for(auto x = 2; x <= SZ; ++ x) res[x] = n % (lpf[x] * res[x / lpf[x]]) ? res[x / lpf[x]] : lpf[x] * res[x / lpf[x]];
return res;
}
bool is_prime(int x) const{
assert(0 <= x && x <= SZ);
return lpf[x] == x;
}
int mu_large(long long x) const{ // O(sqrt(x))
int res = 1;
for(auto i = 2LL; i * i <= x; ++ i) if(x % i == 0){
if(x / i % i) return 0;
x /= i, res = -res;
}
if(x > 1) res = -res;
return res;
}
long long phi_large(long long x) const{ // O(sqrt(x))
long long res = x;
for(auto i = 2LL; i * i <= x; ++ i) if(x % i == 0){
while(x % i == 0) x /= i;
res -= res / i;
}
if(x > 1) res -= res / x;
return res;
}
// returns an array is_prime of length high-low where is_prime[i] = [low+i is a prime]
vector<int> sieve(long long low, long long high) const{
assert(high - 1 <= 1LL * SZ * SZ);
vector<int> is_prime(high - low, true);
for(auto p: prime) for(auto x = max(1LL * p, (low + p - 1) / p) * p; x < high; x += p) is_prime[x - low] = false;
for(auto x = 1; x >= low; -- x) is_prime[x - low] = false;
return is_prime;
}
};
int main(){
cin.tie(0)->sync_with_stdio(0);
cin.exceptions(ios::badbit | ios::failbit);
number_theory nt(1000);
long long n;
cin >> n;
long long cur = 1;
for(auto res = 0; ; ++ res){
if(__builtin_mul_overflow_p(cur, nt.prime[res], 0LL) || cur * nt.prime[res] > n){
cout << res << "\n";
return 0;
}
cur *= nt.prime[res];
}
return 0;
}
/*
*/