結果

問題 No.1653 Squarefree
ユーザー chocoruskchocorusk
提出日時 2021-06-13 15:47:44
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 239 ms / 2,000 ms
コード長 937 bytes
コンパイル時間 813 ms
コンパイル使用メモリ 84,772 KB
実行使用メモリ 15,420 KB
最終ジャッジ日時 2024-04-22 09:02:32
合計ジャッジ時間 8,469 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 237 ms
12,392 KB
testcase_01 AC 20 ms
6,944 KB
testcase_02 AC 21 ms
6,944 KB
testcase_03 AC 21 ms
6,940 KB
testcase_04 AC 21 ms
6,940 KB
testcase_05 AC 21 ms
6,940 KB
testcase_06 AC 21 ms
6,940 KB
testcase_07 AC 21 ms
6,940 KB
testcase_08 AC 21 ms
6,944 KB
testcase_09 AC 21 ms
6,940 KB
testcase_10 AC 21 ms
6,944 KB
testcase_11 AC 215 ms
12,524 KB
testcase_12 AC 221 ms
15,420 KB
testcase_13 AC 223 ms
12,760 KB
testcase_14 AC 226 ms
12,684 KB
testcase_15 AC 211 ms
12,312 KB
testcase_16 AC 222 ms
12,324 KB
testcase_17 AC 225 ms
11,944 KB
testcase_18 AC 226 ms
12,492 KB
testcase_19 AC 219 ms
12,164 KB
testcase_20 AC 232 ms
13,212 KB
testcase_21 AC 228 ms
12,380 KB
testcase_22 AC 232 ms
12,636 KB
testcase_23 AC 223 ms
12,396 KB
testcase_24 AC 233 ms
12,964 KB
testcase_25 AC 225 ms
12,512 KB
testcase_26 AC 230 ms
11,964 KB
testcase_27 AC 226 ms
12,108 KB
testcase_28 AC 224 ms
12,056 KB
testcase_29 AC 228 ms
12,672 KB
testcase_30 AC 224 ms
11,940 KB
testcase_31 AC 230 ms
11,692 KB
testcase_32 AC 239 ms
13,256 KB
testcase_33 AC 230 ms
12,488 KB
testcase_34 AC 216 ms
12,172 KB
testcase_35 AC 226 ms
12,416 KB
testcase_36 AC 21 ms
6,944 KB
testcase_37 AC 21 ms
6,944 KB
testcase_38 AC 22 ms
6,944 KB
testcase_39 AC 21 ms
6,944 KB
testcase_40 AC 21 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <bitset>
#include <cmath>
using namespace std;
typedef long long ll;
const int MAX=2000010;
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;
int main()
{
	ll l, r;
	cin>>l>>r;
    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 m=sqrt(x[i-l]);
        bool sq=0;
		for(int j=-1; j<=1; j++){
		    if((m+j)*(m+j)==x[i-l]) sq=1;
		}
        if(!sq) ans++;
	}
	cout<<ans<<endl;
    return 0;
}
0