結果
| 問題 | No.1653 Squarefree |
| コンテスト | |
| ユーザー |
C
|
| 提出日時 | 2026-11-20 12:45:18 |
| 言語 | C++23(gcc16) (gcc 16.2.0 + boost 1.92.0 + ACL) |
| 結果 |
AC
不安定
|
| 実行時間 | 9 ms / 2,000 ms |
| + 880µs | |
| コード長 | 1,616 bytes |
| 記録 | |
| コンパイル時間 | 7,530 ms |
| コンパイル使用メモリ | 420,484 KB |
| 実行使用メモリ | 9,904 KB |
| 最終ジャッジ日時 | 2026-11-20 12:45:29 |
| 合計ジャッジ時間 | 10,308 ms |
|
ジャッジサーバーID (参考情報) |
judge5_0 / judge3_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 38 |
ソースコード
#if defined(__GNUC__) && !defined(__clang__)
#pragma GCC optimize("O3")
#if defined(__x86_64__) || defined(__i386__)
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#endif
#endif
#include <bits/stdc++.h>
#include <atcoder/all>
#define each(x, v) for (auto&& x : v)
#define each2(x, y, v) for (auto&& [x, y] : v)
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(x) begin(x),end(x)
#define sz(x) (int)(x).size()
using namespace std;
using namespace atcoder;
using ll=long long;
using ull=unsigned long long;
using ld=long double;
using vll=vector<ll>;
using vvll=vector<vll>;
using vi=vector<int>;
using vvi=vector<vi>;
using pll=pair<ll,ll>;
using pi=pair<int,int>;
// using mint=modint998244353;
// using mint=modint1000000007;
// using mint2=static_modint<2>;
// using mint=LazyMontgomeryModInt<998244353>;
// using vm=vector<mint>;
// using vvm=vector<vm>;
#line 2 "math/isqrt.hpp"
#include <cmath>
using namespace std;
// floor(sqrt(n)) を返す (ただし n が負の場合は 0 を返す)
long long isqrt(long long n) {
if (n <= 0) return 0;
long long x = sqrt(n);
while ((x + 1) * (x + 1) <= n) x++;
while (x * x > n) x--;
return x;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
ll L,R;
cin>>L>>R;
const ll B=1000000;
vi squarefree(R-L+1,1);
for(ll a=2;a<=B;++a){
ll s=a*a;
for(ll m=(L+s-1)/s;m*s<=R;++m)squarefree[m*s-L]=0;
}
for(ll b=1;b<=R/((B+1)*(B+1));++b){
ll a=isqrt(R/b);
ll x=a*a*b;
if(x>=L)squarefree[x-L]=0;
}
ll ans=0;
rep(i,0,sz(squarefree))ans+=squarefree[i];
cout<<ans<<'\n';
}
C