結果

問題 No.1653 Squarefree
ユーザー nawawannawawan
提出日時 2021-08-20 23:28:11
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 240 ms / 2,000 ms
コード長 1,227 bytes
コンパイル時間 1,985 ms
コンパイル使用メモリ 203,068 KB
実行使用メモリ 28,744 KB
最終ジャッジ日時 2023-08-04 11:50:07
合計ジャッジ時間 9,360 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 203 ms
27,172 KB
testcase_01 AC 14 ms
6,848 KB
testcase_02 AC 14 ms
6,936 KB
testcase_03 AC 14 ms
6,940 KB
testcase_04 AC 13 ms
6,888 KB
testcase_05 AC 13 ms
7,136 KB
testcase_06 AC 15 ms
7,008 KB
testcase_07 AC 13 ms
6,896 KB
testcase_08 AC 12 ms
6,888 KB
testcase_09 AC 13 ms
6,836 KB
testcase_10 AC 14 ms
6,848 KB
testcase_11 AC 202 ms
27,344 KB
testcase_12 AC 206 ms
27,176 KB
testcase_13 AC 205 ms
27,604 KB
testcase_14 AC 219 ms
27,192 KB
testcase_15 AC 223 ms
27,532 KB
testcase_16 AC 213 ms
27,596 KB
testcase_17 AC 240 ms
27,608 KB
testcase_18 AC 209 ms
27,724 KB
testcase_19 AC 228 ms
27,288 KB
testcase_20 AC 212 ms
27,908 KB
testcase_21 AC 222 ms
27,956 KB
testcase_22 AC 223 ms
28,100 KB
testcase_23 AC 220 ms
27,356 KB
testcase_24 AC 210 ms
26,748 KB
testcase_25 AC 225 ms
27,704 KB
testcase_26 AC 213 ms
27,784 KB
testcase_27 AC 226 ms
28,744 KB
testcase_28 AC 213 ms
27,340 KB
testcase_29 AC 202 ms
27,148 KB
testcase_30 AC 218 ms
27,652 KB
testcase_31 AC 209 ms
27,456 KB
testcase_32 AC 213 ms
27,512 KB
testcase_33 AC 207 ms
27,528 KB
testcase_34 AC 218 ms
27,000 KB
testcase_35 AC 209 ms
27,032 KB
testcase_36 AC 15 ms
6,944 KB
testcase_37 AC 14 ms
6,892 KB
testcase_38 AC 14 ms
6,896 KB
testcase_39 AC 14 ms
6,888 KB
testcase_40 AC 13 ms
6,892 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
int main(){
    long long L, R;
    cin >> L >> R;
    vector<int> fac(1000010);
    iota(fac.begin(), fac.end(), 0);
    for(int i = 2; i < 1000010; i++){
        if(fac[i] != i) continue;
        for(int j = i * 2; j < 1000010; j += i){
            fac[j] = i;
        }
    }
    vector<long long> t(R - L + 1);
    vector<long long> temp;
    vector<int> num(R - L + 1);
    iota(t.begin(), t.end(), L);
    for(int i = 2; i <= 1000010; i++){
        if(fac[i] != i) continue;
        for(long long j = (L + i - 1) / i * i; j <= R; j += i){
            int cnt = 0;
            while(t[j - L] % i == 0){
                t[j - L] /= i;
                cnt++;
            }
            if(cnt > 1) num[j - L] = -1;
        }
    }
    for(int i = 0; i < R - L + 1; i++){
        if(num[i] == 0) temp.push_back(i);
    }
    int ans = temp.size();
    for(int i = 0; i < (int)temp.size(); i++){
        long long ub = 1000000000, lb = 0;
        while(ub - lb > 1){
            long long mid = (ub + lb) / 2;
            if(mid * mid >= t[temp[i]]) ub = mid;
            else lb = mid;
        }
        if(ub != 1 && ub * ub == t[temp[i]]) ans--;
    }
    cout << ans << endl;
}
0