結果

問題 No.1653 Squarefree
ユーザー fumofumofunifumofumofuni
提出日時 2021-08-20 23:46:41
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 1,788 bytes
コンパイル時間 2,487 ms
コンパイル使用メモリ 199,468 KB
実行使用メモリ 103,924 KB
最終ジャッジ日時 2024-04-22 09:28:24
合計ジャッジ時間 25,843 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 381 ms
89,596 KB
testcase_02 AC 384 ms
89,720 KB
testcase_03 AC 384 ms
89,464 KB
testcase_04 AC 385 ms
89,592 KB
testcase_05 AC 380 ms
89,588 KB
testcase_06 AC 383 ms
89,488 KB
testcase_07 AC 386 ms
89,592 KB
testcase_08 AC 381 ms
89,720 KB
testcase_09 AC 383 ms
89,468 KB
testcase_10 AC 389 ms
89,720 KB
testcase_11 AC 580 ms
102,268 KB
testcase_12 AC 572 ms
102,524 KB
testcase_13 AC 609 ms
102,260 KB
testcase_14 AC 608 ms
102,388 KB
testcase_15 AC 618 ms
102,392 KB
testcase_16 AC 613 ms
102,520 KB
testcase_17 AC 605 ms
102,328 KB
testcase_18 AC 610 ms
102,264 KB
testcase_19 AC 597 ms
102,136 KB
testcase_20 AC 598 ms
102,524 KB
testcase_21 AC 605 ms
102,396 KB
testcase_22 AC 596 ms
102,368 KB
testcase_23 AC 598 ms
102,392 KB
testcase_24 AC 605 ms
102,268 KB
testcase_25 AC 602 ms
102,268 KB
testcase_26 AC 602 ms
102,136 KB
testcase_27 AC 626 ms
102,396 KB
testcase_28 AC 621 ms
102,264 KB
testcase_29 AC 623 ms
102,396 KB
testcase_30 AC 589 ms
102,268 KB
testcase_31 AC 611 ms
102,320 KB
testcase_32 AC 619 ms
102,524 KB
testcase_33 AC 622 ms
102,136 KB
testcase_34 AC 619 ms
102,264 KB
testcase_35 AC 611 ms
102,260 KB
testcase_36 AC 386 ms
89,596 KB
testcase_37 AC 386 ms
89,464 KB
testcase_38 AC 392 ms
89,596 KB
testcase_39 AC 383 ms
89,464 KB
testcase_40 AC 381 ms
89,588 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=(n)-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[9]={0,1,-1,0,1,1,-1,-1,0};
const ll dx[9]={1,0,0,-1,1,-1,1,-1,0};
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
int main(){
    vector<ll> dp(1e7,1);
    vector<ll> prime;
    for(int i=2;i<1e7;i++){
        if(!dp[i])continue;
        prime.push_back(i);
        for(int j=i*2;j<1e7;j+=i)dp[j]=0;
    }
    ll l,r;cin >> l >> r;
    vector<ll> dp2(r-l+1);
    for(ll i=0;i<r-l+1;i++)dp2[i]=l+i;
    vector<ll> sq(r-l+1);
    for(auto p:prime){
        ll idx=l/p*p;if(idx<l)idx+=p;
        for(;idx<=r;idx+=p){
            ll cnt=0;
            while(dp2[idx-l]%p==0){
                dp2[idx-l]/=p;cnt++;
            }
            if(cnt>1)sq[idx-l]=1;
        }
    }
    ll p=max(sqrt(l)-1,2.0);
    for(;p*p<=r;p++){
        if(l<=p*p)sq[p*p-l]++;
    }
    ll ans=0;
    for(auto p:sq)if(p)ans++;
    cout << r-l+1-ans << endl;

}      

0