結果

問題 No.1653 Squarefree
ユーザー aut_jul_duraut_jul_dur
提出日時 2021-08-20 23:07:06
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,184 ms / 2,000 ms
コード長 2,267 bytes
コンパイル時間 3,849 ms
コンパイル使用メモリ 229,540 KB
実行使用メモリ 23,864 KB
最終ジャッジ日時 2023-08-04 11:48:47
合計ジャッジ時間 50,595 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,168 ms
23,652 KB
testcase_01 AC 963 ms
5,184 KB
testcase_02 AC 960 ms
5,116 KB
testcase_03 AC 960 ms
5,116 KB
testcase_04 AC 955 ms
5,140 KB
testcase_05 AC 957 ms
5,184 KB
testcase_06 AC 951 ms
5,192 KB
testcase_07 AC 960 ms
5,260 KB
testcase_08 AC 957 ms
5,092 KB
testcase_09 AC 956 ms
5,184 KB
testcase_10 AC 951 ms
5,252 KB
testcase_11 AC 1,111 ms
23,312 KB
testcase_12 AC 1,115 ms
23,264 KB
testcase_13 AC 1,139 ms
23,248 KB
testcase_14 AC 1,171 ms
23,324 KB
testcase_15 AC 1,184 ms
23,220 KB
testcase_16 AC 1,162 ms
23,588 KB
testcase_17 AC 1,141 ms
23,356 KB
testcase_18 AC 1,147 ms
23,336 KB
testcase_19 AC 1,144 ms
23,224 KB
testcase_20 AC 1,116 ms
23,252 KB
testcase_21 AC 1,131 ms
23,204 KB
testcase_22 AC 1,163 ms
23,348 KB
testcase_23 AC 1,134 ms
23,300 KB
testcase_24 AC 1,123 ms
23,140 KB
testcase_25 AC 1,112 ms
23,276 KB
testcase_26 AC 1,112 ms
23,292 KB
testcase_27 AC 1,144 ms
23,340 KB
testcase_28 AC 1,172 ms
23,304 KB
testcase_29 AC 1,165 ms
23,364 KB
testcase_30 AC 1,125 ms
23,864 KB
testcase_31 AC 1,143 ms
23,248 KB
testcase_32 AC 1,149 ms
23,404 KB
testcase_33 AC 1,131 ms
23,244 KB
testcase_34 AC 1,121 ms
23,196 KB
testcase_35 AC 1,163 ms
23,216 KB
testcase_36 AC 948 ms
5,240 KB
testcase_37 AC 947 ms
5,304 KB
testcase_38 AC 949 ms
5,104 KB
testcase_39 AC 952 ms
5,236 KB
testcase_40 AC 947 ms
5,256 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
const long long MOD = 1000000007;
const long long INF = 9*1e18;
using ll = long long;
using mint = modint1000000007;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
long double PI = 3.14159265358979;

vector<ll> primelist;

bool Prime(ll num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false;
 
    double sqrtNum = sqrt(num);
    for (ll i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return false;
        }
    }
    return true;
}

void primeinput(){
  for(ll i = 2;i<2002000;i++){
    if(Prime(i)){
      primelist.push_back(i);
    }
  }
}



int main(){
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  ll L,R;
  cin>>L>>R;
  primeinput();
  vector<ll> A,B;
  for(ll i = L;i<=R;i++){
    A.push_back(i);
    B.push_back(0);
  }
  rep(i,primelist.size()){
    ll temp = 0;
    if(primelist[i] >= L){
      temp = primelist[i]-L;
    }
    else if(L%primelist[i] == 0){
      temp = 0;
    }
    else{
      temp = primelist[i]-(L%primelist[i]);
    }
   // cout << primelist[i] << " " << temp << endl;
    while(1){
      if(temp >= A.size()){
        break;
      }
      ll cnt = 0;
      while(A[temp]%primelist[i] == 0){
        if(primelist[i] == 7){
         // cout << A[temp] << " " << primelist[i] << endl;
        }
        A[temp]/=primelist[i];
        cnt++;
      }
      if(cnt >= 2){
        B[temp] = 1;
      }
      temp += primelist[i];
    }
  }
  /*rep(i,B.size()){
    cout << B[i] << " ";
  }
  cout << endl;*/
  ll ans = 0;
  rep(i,A.size()){
    if(B[i] == 1){
      continue;
    }
    if(A[i] == 1 && B[i] != 1){
      ans++;
      continue;
    }
    ll temp = sqrt(A[i]);
    //cout << temp << endl;
    bool d = 0;
    for(int k = -10;k<=10;k++){
      if((temp+k)*(temp+k) == A[i]){
        d = 1;
      }
    }
    if(!d){
      //cout << L+i << endl;
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}
0