結果
問題 | No.1653 Squarefree |
ユーザー | sgsw |
提出日時 | 2021-08-27 15:35:03 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 4,373 bytes |
コンパイル時間 | 2,470 ms |
コンパイル使用メモリ | 210,768 KB |
実行使用メモリ | 36,432 KB |
最終ジャッジ日時 | 2024-11-20 16:00:08 |
合計ジャッジ時間 | 85,934 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | TLE | - |
testcase_01 | AC | 48 ms
16,896 KB |
testcase_02 | AC | 53 ms
18,492 KB |
testcase_03 | AC | 51 ms
16,896 KB |
testcase_04 | AC | 51 ms
31,240 KB |
testcase_05 | AC | 46 ms
18,624 KB |
testcase_06 | AC | 48 ms
16,896 KB |
testcase_07 | AC | 48 ms
31,180 KB |
testcase_08 | AC | 45 ms
16,976 KB |
testcase_09 | AC | 46 ms
17,024 KB |
testcase_10 | AC | 50 ms
31,180 KB |
testcase_11 | TLE | - |
testcase_12 | TLE | - |
testcase_13 | TLE | - |
testcase_14 | TLE | - |
testcase_15 | TLE | - |
testcase_16 | TLE | - |
testcase_17 | TLE | - |
testcase_18 | TLE | - |
testcase_19 | TLE | - |
testcase_20 | TLE | - |
testcase_21 | TLE | - |
testcase_22 | TLE | - |
testcase_23 | TLE | - |
testcase_24 | TLE | - |
testcase_25 | TLE | - |
testcase_26 | TLE | - |
testcase_27 | TLE | - |
testcase_28 | TLE | - |
testcase_29 | TLE | - |
testcase_30 | TLE | - |
testcase_31 | TLE | - |
testcase_32 | TLE | - |
testcase_33 | TLE | - |
testcase_34 | TLE | - |
testcase_35 | TLE | - |
testcase_36 | AC | 46 ms
11,600 KB |
testcase_37 | AC | 49 ms
11,520 KB |
testcase_38 | AC | 48 ms
11,596 KB |
testcase_39 | AC | 49 ms
11,648 KB |
testcase_40 | AC | 50 ms
36,432 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++){ 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; }