結果

問題 No.1653 Squarefree
ユーザー chocoruskchocorusk
提出日時 2021-06-13 04:30:15
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 281 ms / 2,000 ms
コード長 1,202 bytes
コンパイル時間 7,768 ms
コンパイル使用メモリ 243,944 KB
実行使用メモリ 12,032 KB
最終ジャッジ日時 2024-04-22 09:02:49
合計ジャッジ時間 16,191 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 269 ms
11,904 KB
testcase_01 AC 12 ms
5,248 KB
testcase_02 AC 11 ms
5,376 KB
testcase_03 AC 12 ms
5,376 KB
testcase_04 AC 11 ms
5,376 KB
testcase_05 AC 12 ms
5,376 KB
testcase_06 AC 12 ms
5,376 KB
testcase_07 AC 12 ms
5,376 KB
testcase_08 AC 11 ms
5,376 KB
testcase_09 AC 11 ms
5,376 KB
testcase_10 AC 11 ms
5,376 KB
testcase_11 AC 190 ms
11,904 KB
testcase_12 AC 204 ms
11,776 KB
testcase_13 AC 264 ms
11,904 KB
testcase_14 AC 259 ms
11,904 KB
testcase_15 AC 262 ms
11,904 KB
testcase_16 AC 271 ms
11,904 KB
testcase_17 AC 264 ms
11,904 KB
testcase_18 AC 259 ms
12,032 KB
testcase_19 AC 261 ms
11,904 KB
testcase_20 AC 269 ms
11,776 KB
testcase_21 AC 274 ms
11,904 KB
testcase_22 AC 245 ms
11,904 KB
testcase_23 AC 266 ms
11,776 KB
testcase_24 AC 250 ms
11,776 KB
testcase_25 AC 247 ms
12,032 KB
testcase_26 AC 281 ms
11,904 KB
testcase_27 AC 247 ms
12,032 KB
testcase_28 AC 242 ms
11,904 KB
testcase_29 AC 254 ms
11,904 KB
testcase_30 AC 254 ms
11,776 KB
testcase_31 AC 258 ms
11,904 KB
testcase_32 AC 257 ms
11,904 KB
testcase_33 AC 254 ms
12,032 KB
testcase_34 AC 258 ms
12,032 KB
testcase_35 AC 244 ms
11,904 KB
testcase_36 AC 12 ms
5,376 KB
testcase_37 AC 11 ms
5,376 KB
testcase_38 AC 11 ms
5,376 KB
testcase_39 AC 12 ms
5,376 KB
testcase_40 AC 11 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <bitset>
#include "testlib.h"
using namespace std;
typedef long long ll;
const int MAX=1000010;
bitset<MAX> isprime;
void sieve(){
	for(int i=3; i<MAX; i++, i++) isprime[i]=1;
	isprime[2]=1;
	for(int i=3; i<MAX; i++){
		if(isprime[i]){
			for(int j=(i<<1); j<MAX; j+=i) isprime[j]=0;
		}
	}
}
ll x[MAX];
bitset<MAX> sqf;
const ll MAXD=1000000;
const ll MAXR=1000000000000000000ll;
int main(int argc, char* argv[]){
    registerValidation(argc, argv);
    ll l=inf.readLong(1ll, MAXR);
    inf.readSpace();
    ll r=inf.readLong(1ll, MAXR);
    ensure(l<=r && r-l<=MAXD);
    inf.readEoln();
    inf.readEof();
    
    sieve();
	for(ll i=l; i<=r; i++){
		x[i-l]=i;
		sqf[i-l]=1;
	}
	for(ll p=2; p<MAX; p++){
		if(!isprime[p]) continue;
		for(ll i=(l+p-1)/p*p; i<=r; i+=p){
			int e=0;
			while(x[i-l]%p==0){
				x[i-l]/=p;
				e++;
			}
			if(e>1) sqf[i-l]=0;
		}
	}
	int ans=0;
	for(ll i=l; i<=r; i++){
		if(!sqf[i-l]) continue;
        if(x[i-l]==1){
            ans++;
            continue;
        }
		ll xl=1, xr=1e9+7;
		while(xr-xl>1){
			ll xm=(xl+xr)/2;
			if(xm*xm<=x[i-l]) xl=xm;
			else xr=xm;
		}
		if(xl*xl!=x[i-l]) ans++;
	}
	cout<<ans<<endl;
    return 0;
}
0