結果

問題 No.1653 Squarefree
ユーザー sigma425sigma425
提出日時 2021-08-20 22:35:01
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 198 ms / 2,000 ms
コード長 2,758 bytes
コンパイル時間 2,532 ms
コンパイル使用メモリ 205,608 KB
実行使用メモリ 16,500 KB
最終ジャッジ日時 2023-08-04 11:31:12
合計ジャッジ時間 9,183 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 194 ms
16,308 KB
testcase_01 AC 14 ms
7,668 KB
testcase_02 AC 15 ms
7,620 KB
testcase_03 AC 14 ms
7,668 KB
testcase_04 AC 14 ms
7,832 KB
testcase_05 AC 14 ms
7,784 KB
testcase_06 AC 14 ms
7,552 KB
testcase_07 AC 15 ms
7,624 KB
testcase_08 AC 15 ms
7,788 KB
testcase_09 AC 15 ms
7,840 KB
testcase_10 AC 14 ms
7,792 KB
testcase_11 AC 152 ms
16,324 KB
testcase_12 AC 156 ms
16,308 KB
testcase_13 AC 181 ms
16,488 KB
testcase_14 AC 194 ms
16,180 KB
testcase_15 AC 177 ms
16,324 KB
testcase_16 AC 186 ms
16,372 KB
testcase_17 AC 193 ms
16,320 KB
testcase_18 AC 198 ms
16,388 KB
testcase_19 AC 178 ms
16,304 KB
testcase_20 AC 171 ms
16,428 KB
testcase_21 AC 175 ms
16,456 KB
testcase_22 AC 191 ms
16,460 KB
testcase_23 AC 184 ms
16,164 KB
testcase_24 AC 178 ms
16,364 KB
testcase_25 AC 192 ms
16,308 KB
testcase_26 AC 176 ms
16,148 KB
testcase_27 AC 182 ms
16,500 KB
testcase_28 AC 177 ms
16,436 KB
testcase_29 AC 167 ms
16,388 KB
testcase_30 AC 176 ms
16,228 KB
testcase_31 AC 170 ms
16,364 KB
testcase_32 AC 184 ms
16,440 KB
testcase_33 AC 189 ms
16,416 KB
testcase_34 AC 187 ms
16,500 KB
testcase_35 AC 176 ms
16,312 KB
testcase_36 AC 14 ms
7,784 KB
testcase_37 AC 15 ms
7,568 KB
testcase_38 AC 15 ms
7,664 KB
testcase_39 AC 14 ms
7,560 KB
testcase_40 AC 14 ms
7,876 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using uint = unsigned int;
using ull = unsigned long long;
#define rep(i,n) for(int i=0;i<int(n);i++)
#define rep1(i,n) for(int i=1;i<=int(n);i++)
#define per(i,n) for(int i=int(n)-1;i>=0;i--)
#define per1(i,n) for(int i=int(n);i>0;i--)
#define all(c) c.begin(),c.end()
#define si(x) int(x.size())
#define pb emplace_back
#define fs first
#define sc second
template<class T> using V = vector<T>;
template<class T> using VV = vector<vector<T>>;
template<class T,class U> void chmax(T& x, U y){if(x<y) x=y;}
template<class T,class U> void chmin(T& x, U y){if(y<x) x=y;}
template<class T> void mkuni(V<T>& v){sort(all(v));v.erase(unique(all(v)),v.end());}
template<class T> int lwb(const V<T>& v, const T& a){return lower_bound(all(v),a) - v.begin();}
template<class T>
V<T> Vec(size_t a) {
    return V<T>(a);
}
template<class T, class... Ts>
auto Vec(size_t a, Ts... ts) {
  return V<decltype(Vec<T>(ts...))>(a, Vec<T>(ts...));
}
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
	return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
	o<<"{";
	for(const T& v:vc) o<<v<<",";
	o<<"}";
	return o;
}
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

#ifdef LOCAL
#define show(x) cerr << "LINE" << __LINE__ << " : " << #x << " = " << (x) << endl
void dmpr(ostream& os){os<<endl;}
template<class T,class... Args>
void dmpr(ostream&os,const T&t,const Args&... args){
	os<<t<<" ~ ";
	dmpr(os,args...);
}
#define shows(...) cerr << "LINE" << __LINE__ << " : ";dmpr(cerr,##__VA_ARGS__)
#define dump(x) cerr << "LINE" << __LINE__ << " : " << #x << " = {";  \
	for(auto v: x) cerr << v << ","; cerr << "}" << endl;
#else
#define show(x) void(0)
#define dump(x) void(0)
#define shows(...) void(0)
#endif
V<bool> isp;
V<int> pr;
V<int> sf; //smallest factor, sf[9*5*11] = 3
void linear_sieve(int X){		// <= X
	isp = V<bool>(X+1,true); isp[0] = isp[1] = false;
	sf = V<int>(X+1);
	for(int i=2;i<=X;i++){
		if(isp[i]){
			pr.pb(i);
			sf[i] = i;
		}
		for(int j=0;i*pr[j]<=X;j++){
			isp[i*pr[j]] = false;
			sf[i*pr[j]] = pr[j];
			if(i%pr[j] == 0) break;
		}
	}
}

const ll X = 1000010;
ll f[X];
bool sq[X];

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);		//DON'T USE scanf/printf/puts !!
	cout << fixed << setprecision(20);

	linear_sieve(X);

	ll L,R; cin >> L >> R;
	rep(i,R-L+1){
		f[i] = L+i;
	}
	for(ll p: pr){
		for(ll x=(L+p-1)/p*p; x<=R; x+=p){
			f[x-L] /= p;
			while(f[x-L]%p == 0){
				f[x-L] /= p;
				sq[x-L] = true;
			}
		}
	}
	ll ans = 0;
	rep(i,R-L+1){
		if(f[i] > 1){
			ll r = sqrtl(f[i]);
			if(r*r == f[i]) sq[i] = true;
		}
		if(!sq[i]) ans++;
	}
	cout << ans << endl;
}
0