結果

問題 No.1653 Squarefree
ユーザー aut_jul_duraut_jul_dur
提出日時 2021-08-20 23:00:04
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,209 bytes
コンパイル時間 4,143 ms
コンパイル使用メモリ 225,576 KB
実行使用メモリ 20,412 KB
最終ジャッジ日時 2024-04-22 06:57:33
合計ジャッジ時間 26,519 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 357 ms
6,816 KB
testcase_02 AC 356 ms
6,940 KB
testcase_03 AC 357 ms
6,944 KB
testcase_04 AC 355 ms
6,940 KB
testcase_05 AC 356 ms
6,940 KB
testcase_06 WA -
testcase_07 AC 359 ms
6,940 KB
testcase_08 AC 356 ms
6,940 KB
testcase_09 AC 356 ms
6,944 KB
testcase_10 AC 356 ms
6,944 KB
testcase_11 AC 570 ms
19,552 KB
testcase_12 AC 569 ms
19,756 KB
testcase_13 AC 585 ms
19,464 KB
testcase_14 WA -
testcase_15 AC 578 ms
19,568 KB
testcase_16 AC 578 ms
19,552 KB
testcase_17 AC 577 ms
19,536 KB
testcase_18 WA -
testcase_19 AC 583 ms
19,460 KB
testcase_20 WA -
testcase_21 AC 585 ms
19,588 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 AC 586 ms
19,612 KB
testcase_25 AC 587 ms
19,724 KB
testcase_26 WA -
testcase_27 AC 582 ms
19,684 KB
testcase_28 AC 571 ms
19,536 KB
testcase_29 AC 581 ms
19,632 KB
testcase_30 WA -
testcase_31 AC 587 ms
19,740 KB
testcase_32 AC 582 ms
19,536 KB
testcase_33 WA -
testcase_34 AC 571 ms
19,688 KB
testcase_35 AC 585 ms
19,572 KB
testcase_36 AC 357 ms
6,944 KB
testcase_37 AC 357 ms
6,940 KB
testcase_38 AC 357 ms
6,940 KB
testcase_39 WA -
testcase_40 AC 357 ms
6,940 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<1002000;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{
      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 = -1;k<=1;k++){
      if((temp+k)*(temp+k) == A[i]){
        d = 1;
      }
    }
    if(!d){
      //cout << L+i << endl;
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}
0