結果
問題 | No.1653 Squarefree |
ユーザー | sgsw |
提出日時 | 2021-08-27 15:36:36 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 342 ms / 2,000 ms |
コード長 | 4,376 bytes |
コンパイル時間 | 2,488 ms |
コンパイル使用メモリ | 210,804 KB |
実行使用メモリ | 19,536 KB |
最終ジャッジ日時 | 2024-11-20 16:02:18 |
合計ジャッジ時間 | 13,222 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 328 ms
19,532 KB |
testcase_01 | AC | 49 ms
11,664 KB |
testcase_02 | AC | 48 ms
11,728 KB |
testcase_03 | AC | 45 ms
11,600 KB |
testcase_04 | AC | 49 ms
11,600 KB |
testcase_05 | AC | 56 ms
11,648 KB |
testcase_06 | AC | 52 ms
11,540 KB |
testcase_07 | AC | 48 ms
11,624 KB |
testcase_08 | AC | 48 ms
11,508 KB |
testcase_09 | AC | 46 ms
11,724 KB |
testcase_10 | AC | 47 ms
11,648 KB |
testcase_11 | AC | 308 ms
19,504 KB |
testcase_12 | AC | 318 ms
19,388 KB |
testcase_13 | AC | 307 ms
19,276 KB |
testcase_14 | AC | 322 ms
19,404 KB |
testcase_15 | AC | 326 ms
19,480 KB |
testcase_16 | AC | 315 ms
19,532 KB |
testcase_17 | AC | 322 ms
19,424 KB |
testcase_18 | AC | 332 ms
19,528 KB |
testcase_19 | AC | 331 ms
19,408 KB |
testcase_20 | AC | 339 ms
19,536 KB |
testcase_21 | AC | 330 ms
19,504 KB |
testcase_22 | AC | 325 ms
19,472 KB |
testcase_23 | AC | 316 ms
19,408 KB |
testcase_24 | AC | 327 ms
19,280 KB |
testcase_25 | AC | 335 ms
19,536 KB |
testcase_26 | AC | 334 ms
19,404 KB |
testcase_27 | AC | 342 ms
19,436 KB |
testcase_28 | AC | 313 ms
19,428 KB |
testcase_29 | AC | 318 ms
19,536 KB |
testcase_30 | AC | 323 ms
19,400 KB |
testcase_31 | AC | 328 ms
19,520 KB |
testcase_32 | AC | 326 ms
19,464 KB |
testcase_33 | AC | 326 ms
19,344 KB |
testcase_34 | AC | 328 ms
19,464 KB |
testcase_35 | AC | 335 ms
19,488 KB |
testcase_36 | AC | 51 ms
11,596 KB |
testcase_37 | AC | 46 ms
11,648 KB |
testcase_38 | AC | 48 ms
11,548 KB |
testcase_39 | AC | 50 ms
11,648 KB |
testcase_40 | AC | 52 ms
11,648 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; }