結果
問題 | No.1653 Squarefree |
ユーザー |
👑 ![]() |
提出日時 | 2025-03-25 14:48:20 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 288 ms / 2,000 ms |
コード長 | 2,837 bytes |
コンパイル時間 | 1,050 ms |
コンパイル使用メモリ | 80,208 KB |
実行使用メモリ | 19,000 KB |
最終ジャッジ日時 | 2025-03-25 14:48:30 |
合計ジャッジ時間 | 9,263 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 38 |
ソースコード
#ifdef NACHIA#define _GLIBCXX_DEBUG#else#define NDEBUG#endif#include <iostream>#include <string>#include <vector>#include <algorithm>#include <set>using i64 = long long;using u64 = unsigned long long;#define rep(i,n) for(i64 i=0; i<i64(n); i++)const i64 INF = 1001001001001001001;template<typename A> void chmin(A& l, const A& r){ if(r < l) l = r; }template<typename A> void chmax(A& l, const A& r){ if(l < r) l = r; }using namespace std;#include <cassert>namespace nachia{namespace internal{// mod 2^64constexpr unsigned long long PowerOfULongLong(unsigned long long a, unsigned long long i){unsigned long long res = 1;while(i){ if(i&1){ res *= a; } i /= 2; a *= a; }return res;}}unsigned long long FloorOfKthRoot(unsigned long long real, unsigned long long k){using u64 = unsigned long long;assert(k != 0);if(real <= 1) return real;if(k >= 64) return 1;if(k == 1) return real;struct Precalc{// a^i <= xstatic constexpr bool lesseq(u64 a, int i, u64 x) {if (a == 0) return true;for(int j=0; j<i; j++) x /= a;return x >= 1;}unsigned long long BORDER[64];constexpr Precalc() : BORDER() {for (int idx = 2; idx <= 63; idx++) {u64 l = 0, r = 1ull << 33;while (l + 1 < r) {u64 m = (l + r) / 2;if (lesseq(m, idx, ~0ull)) l = m;else r = m;}BORDER[idx] = r;}};};constexpr Precalc precalc;u64 l = 0, r = precalc.BORDER[k];if(real < r) r = real;while (l + 1 < r) {u64 m = (l + r) / 2;if(internal::PowerOfULongLong(m, k) <= real) l = m;else r = m;}return l;}unsigned long long CeilOfKthRoot(unsigned long long real, unsigned long long k){if(real <= 1) return real;if(k >= 64) return 2;if(k == 1) return real;unsigned long long x = FloorOfKthRoot(real, k);if(internal::PowerOfULongLong(x, k) != real) x++;return x;}} // namespace nachiavoid testcase(){i64 L, R; cin >> L >> R;vector<i64> X(R-L+1);rep(i,X.size()) X[i] = L+i;vector<i64> sieve(1000001, 1);for(i64 p=2; p<=1000000; p++) if(sieve[p]){for(i64 q=p*p; q<sieve.size(); q+=p) sieve[q] = 0;for(i64 q=(L+p-1)/p*p; q<=R; q+=p) if(X[q-L] != 0){if(X[q-L] % (p*p) == 0) X[q-L] = 0;else if(X[q-L] % p == 0) X[q-L] /= p;}}i64 ans = 0;for(i64 x : X) if(x != 0){i64 y = x == 1 ? 0 : nachia::FloorOfKthRoot(x, 2);if(y*y != x) ans += 1;}cout << ans << "\n";}int main(){ios::sync_with_stdio(false); cin.tie(nullptr);testcase();return 0;}