結果
問題 | No.1653 Squarefree |
ユーザー | sgsw |
提出日時 | 2021-08-27 15:36:36 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 297 ms / 2,000 ms |
コード長 | 4,376 bytes |
コンパイル時間 | 2,484 ms |
コンパイル使用メモリ | 211,872 KB |
実行使用メモリ | 19,640 KB |
最終ジャッジ日時 | 2024-04-30 18:34:44 |
合計ジャッジ時間 | 11,905 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 283 ms
19,468 KB |
testcase_01 | AC | 38 ms
11,540 KB |
testcase_02 | AC | 40 ms
11,652 KB |
testcase_03 | AC | 42 ms
11,608 KB |
testcase_04 | AC | 38 ms
11,596 KB |
testcase_05 | AC | 38 ms
11,616 KB |
testcase_06 | AC | 38 ms
11,692 KB |
testcase_07 | AC | 38 ms
11,656 KB |
testcase_08 | AC | 39 ms
11,728 KB |
testcase_09 | AC | 40 ms
11,720 KB |
testcase_10 | AC | 37 ms
11,572 KB |
testcase_11 | AC | 254 ms
19,628 KB |
testcase_12 | AC | 252 ms
19,476 KB |
testcase_13 | AC | 284 ms
19,372 KB |
testcase_14 | AC | 288 ms
19,292 KB |
testcase_15 | AC | 287 ms
19,456 KB |
testcase_16 | AC | 280 ms
19,348 KB |
testcase_17 | AC | 289 ms
19,448 KB |
testcase_18 | AC | 274 ms
19,324 KB |
testcase_19 | AC | 281 ms
19,312 KB |
testcase_20 | AC | 268 ms
19,536 KB |
testcase_21 | AC | 277 ms
19,456 KB |
testcase_22 | AC | 263 ms
19,428 KB |
testcase_23 | AC | 262 ms
19,416 KB |
testcase_24 | AC | 268 ms
19,332 KB |
testcase_25 | AC | 269 ms
19,312 KB |
testcase_26 | AC | 262 ms
19,412 KB |
testcase_27 | AC | 267 ms
19,496 KB |
testcase_28 | AC | 272 ms
19,480 KB |
testcase_29 | AC | 267 ms
19,552 KB |
testcase_30 | AC | 258 ms
19,284 KB |
testcase_31 | AC | 278 ms
19,364 KB |
testcase_32 | AC | 271 ms
19,476 KB |
testcase_33 | AC | 272 ms
19,640 KB |
testcase_34 | AC | 278 ms
19,412 KB |
testcase_35 | AC | 297 ms
19,460 KB |
testcase_36 | AC | 43 ms
11,652 KB |
testcase_37 | AC | 42 ms
11,668 KB |
testcase_38 | AC | 43 ms
11,476 KB |
testcase_39 | AC | 42 ms
11,632 KB |
testcase_40 | AC | 42 ms
11,668 KB |
ソースコード
#include<bits/stdc++.h> using namespace std; #pragma GCC optimize("Ofast") #define ll long long #define ld long double #define rep(i, a, b) for (int i = a; i < b; i++) #define rep1(i, a, b) for (int i = (b) - 1; i >= a; i--) #define endl '\n' #define vvii vector<vector<int>> #define vi vector<int> #define vvll vector<vector<ll>> #define vl vector<ll> template<class T> ostream& operator << (ostream &s, vector<T> &P) { for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; } template <class T>bool chmax(T &a, T b){if (a < b){a = b;return true;}return false;} template <class T>bool chmin(T &a, T b){if (a > b){a = b;return true;}return false;} template <class T = int>T gcd(T a, T b){return (b == 0) ? a : gcd(b, a % b);} template <class T = int>T lcm(T a, T b){return a / gcd(a, b) * b;} template<class T = int>T powMod(T x, T k, T m) {if (k == 0){return (T)1;}if (k % 2 == 0) {return powMod(x*x % m, k/2, m);}else{return x*powMod(x, k-1, m) % m;}} template <class T = int>T extgcd(T a,T b,T &x,T &y){T g = a;x = 1;y = 0;if (b != 0) {g = extgcd(b, a % b, y, x), y -= (a / b) * x;}return g;} template<class T = int> T invMod(T a,T m){T x,y;if (extgcd(a, m, x, y) == 1) {return (x + m) % m;}else{return -1;}} using Pii = pair<int,int>; using Pll = pair<ll,ll>; struct Eratos { vector<int> primes; vector<bool> isprime; vector<int> mebius; vector<int> min_factor; Eratos(int MAX) : primes(), isprime(MAX + 1, true), mebius(MAX + 1, 1), min_factor(MAX + 1, -1) { isprime[0] = isprime[1] = false; min_factor[0] = 0, min_factor[1] = 1; for (int i = 2; i <= MAX; ++i) { if (!isprime[i]) continue; primes.push_back(i); mebius[i] = -1; min_factor[i] = i; for (int j = i * 2; j <= MAX; j += i) { isprime[j] = false; if ((j / i) % i == 0) mebius[j] = 0; else mebius[j] = -mebius[j]; if (min_factor[j] == -1) min_factor[j] = i; } } } // prime factorization vector<pair<int, int>> prime_factors(int n) { vector<pair<int, int>> res; while (n != 1) { int prime = min_factor[n]; int exp = 0; while (min_factor[n] == prime) { ++exp; n /= prime; } res.push_back(make_pair(prime, exp)); } return res; } // enumerate divisors vector<int> divisors(int n) { vector<int> res({1}); auto pf = prime_factors(n); for (auto p : pf) { int n = (int)res.size(); for (int i = 0; i < n; ++i) { int v = 1; for (int j = 0; j < p.second; ++j) { v *= p.first; res.push_back(res[i] * v); } } } return res; } }; const int maxn = 1e6 + 10; Eratos Primes(maxn); bool is_square(ll x){ ll l = 1; //l * l <= x ll r = 1e9 + 5; // l * l > x while (r - l > 1){ ll med = (r + l) / 2; if (med * med <= x){ l = med; }else{ r = med; } } if (l * l == x){ return true; }else{ return false; } } signed main(){ ios::sync_with_stdio(false); cin.tie(nullptr); ll L,R; cin >> L >> R; vector<ll> valid(R - L + 1); vector<bool> ok(R - L + 1); for (ll i = 0; i <= R - L;i++){ valid[i] = i + L; ok[i] = true; } for (int p : Primes.primes){ ll q = p; for (ll d = (L + q - 1) / q * q; d <= R;d += q){ int ord = 0; while(valid[d - L] % q == 0){ valid[d - L] /= q; ord++; } if (ord >= 2){ ok[d - L] = false; } } } int ans = 0; for (ll i = 0; i <= R - L;i++){ if (!ok[i]){ continue; } ans++; ll x = valid[i]; if (is_square(x) && x > 1){ ans--; } } cout << ans << endl; return 0; }