結果

問題 No.1653 Squarefree
ユーザー chocoruskchocorusk
提出日時 2021-06-13 04:07:31
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 276 ms / 2,000 ms
コード長 922 bytes
コンパイル時間 784 ms
コンパイル使用メモリ 73,312 KB
実行使用メモリ 11,648 KB
最終ジャッジ日時 2024-04-22 09:02:06
合計ジャッジ時間 9,188 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 274 ms
11,524 KB
testcase_01 AC 11 ms
5,376 KB
testcase_02 AC 12 ms
5,376 KB
testcase_03 AC 12 ms
5,376 KB
testcase_04 AC 11 ms
5,376 KB
testcase_05 AC 11 ms
5,376 KB
testcase_06 AC 11 ms
5,376 KB
testcase_07 AC 11 ms
5,376 KB
testcase_08 AC 12 ms
5,376 KB
testcase_09 AC 11 ms
5,376 KB
testcase_10 AC 11 ms
5,376 KB
testcase_11 AC 202 ms
11,648 KB
testcase_12 AC 211 ms
11,648 KB
testcase_13 AC 269 ms
11,648 KB
testcase_14 AC 269 ms
11,520 KB
testcase_15 AC 259 ms
11,492 KB
testcase_16 AC 251 ms
11,520 KB
testcase_17 AC 255 ms
11,648 KB
testcase_18 AC 259 ms
11,484 KB
testcase_19 AC 273 ms
11,608 KB
testcase_20 AC 256 ms
11,648 KB
testcase_21 AC 269 ms
11,520 KB
testcase_22 AC 272 ms
11,648 KB
testcase_23 AC 263 ms
11,520 KB
testcase_24 AC 271 ms
11,424 KB
testcase_25 AC 275 ms
11,648 KB
testcase_26 AC 270 ms
11,648 KB
testcase_27 AC 276 ms
11,648 KB
testcase_28 AC 268 ms
11,640 KB
testcase_29 AC 275 ms
11,520 KB
testcase_30 AC 265 ms
11,576 KB
testcase_31 AC 274 ms
11,576 KB
testcase_32 AC 273 ms
11,648 KB
testcase_33 AC 259 ms
11,632 KB
testcase_34 AC 265 ms
11,648 KB
testcase_35 AC 263 ms
11,520 KB
testcase_36 AC 11 ms
5,376 KB
testcase_37 AC 12 ms
5,376 KB
testcase_38 AC 11 ms
5,376 KB
testcase_39 AC 11 ms
5,376 KB
testcase_40 AC 11 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <bitset>
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;
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 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