結果

問題 No.1653 Squarefree
ユーザー 👑 potato167potato167
提出日時 2021-08-21 12:15:27
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,798 bytes
コンパイル時間 2,297 ms
コンパイル使用メモリ 198,368 KB
実行使用メモリ 7,552 KB
最終ジャッジ日時 2024-04-23 04:03:22
合計ジャッジ時間 4,824 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 33 ms
7,196 KB
testcase_02 AC 34 ms
7,224 KB
testcase_03 AC 34 ms
7,296 KB
testcase_04 AC 34 ms
7,120 KB
testcase_05 AC 34 ms
7,264 KB
testcase_06 AC 34 ms
7,312 KB
testcase_07 AC 34 ms
7,196 KB
testcase_08 AC 34 ms
7,372 KB
testcase_09 AC 34 ms
7,296 KB
testcase_10 AC 34 ms
7,316 KB
testcase_11 AC 34 ms
7,300 KB
testcase_12 AC 34 ms
7,316 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 AC 34 ms
7,232 KB
testcase_37 AC 45 ms
7,300 KB
testcase_38 AC 33 ms
7,328 KB
testcase_39 AC 34 ms
7,368 KB
testcase_40 AC 34 ms
7,232 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#define _GLIBCXX_DEBUG
using namespace std;
using std::cout;
using std::cin;
using std::endl;
using ll=long long;
using ld=long double;
ll ILL=1167167167167167167;
const int INF=2100000000;
ll mod=998244353;
#define rep(i,a) for (ll i=0;i<a;i++)
template<class T> using _pq = priority_queue<T, vector<T>, greater<T>>;
template<class T> ll LB(vector<T> &v,T a){return lower_bound(v.begin(),v.end(),a)-v.begin();}
template<class T> ll UB(vector<T> &v,T a){return upper_bound(v.begin(),v.end(),a)-v.begin();}
template<class T> bool chmin(T &a,const T &b){if(a>b){a=b;return 1;}else return 0;}
template<class T> bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}else return 0;}
template<class T> void So(vector<T> &v) {sort(v.begin(),v.end());}
template<class T> void Sore(vector<T> &v) {sort(v.begin(),v.end(),[](T x,T y){return x>y;});}
void yneos(bool a){if(a) cout<<"Yes\n"; else cout<<"No\n";}

vector<int> Mobius(int N){
	vector<int> ans(N+1,-1);
	vector<bool> p(N+1,true);
	ans[0]=0,ans[1]=1;
	for(int i=2;i*i<=N;i++){
		if(p[i]){
			for(int j=i*2;j<=N;j+=i){
				if(p[j]){
					p[j]=false;
				}
				else ans[j]*=-1;
			}
			for(int j=i*i;j<=N;j+=i*i){
				ans[j]=0;
			}
		}
	}
	return ans;
}

//おちこんだりもしたけれど、私はげんきです。
int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	
	ll L,R;
	cin>>L>>R;
	ll ans=R-L+1;
	ll M=1e6;
	auto mo=Mobius(M);
	/*rep(i,11) cout<<mo[i]<<" ";
	cout<<endl;*/
	for(ll i=2;i<=M;i++){
		ll x=i*i;
		ans+=mo[i]*(R/x-(L-1)/x);
	}
	if(L>M*M){
		ll l=M,r=1e9+1;
		while(r-l>1){
			ll D=(l+r)/2;
			if(L>D*D) l=D;
			else r=D;
		}
		if(r*r<=R){
			ans--;
			rep(i,M){
				if(i<2) continue;
				if(r%i==0){
					ans++;
					break;
				}
			}
		}
	}
	cout<<ans<<"\n";
}
0