結果

問題 No.1567 Integer Coefficient Equation
ユーザー umezoumezo
提出日時 2021-06-26 14:28:28
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,514 bytes
コンパイル時間 2,458 ms
コンパイル使用メモリ 201,724 KB
実行使用メモリ 7,956 KB
最終ジャッジ日時 2023-09-07 16:40:15
合計ジャッジ時間 10,210 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 14 ms
7,868 KB
testcase_01 AC 14 ms
7,644 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 16 ms
7,720 KB
testcase_08 AC 14 ms
7,640 KB
testcase_09 AC 16 ms
7,936 KB
testcase_10 AC 14 ms
7,636 KB
testcase_11 AC 15 ms
7,644 KB
testcase_12 AC 14 ms
7,724 KB
testcase_13 AC 15 ms
7,820 KB
testcase_14 AC 16 ms
7,868 KB
testcase_15 AC 16 ms
7,812 KB
testcase_16 WA -
testcase_17 AC 184 ms
7,640 KB
testcase_18 AC 184 ms
7,808 KB
testcase_19 AC 183 ms
7,748 KB
testcase_20 AC 185 ms
7,864 KB
testcase_21 AC 185 ms
7,700 KB
testcase_22 AC 188 ms
7,812 KB
testcase_23 AC 185 ms
7,752 KB
testcase_24 AC 185 ms
7,936 KB
testcase_25 AC 185 ms
7,812 KB
testcase_26 AC 187 ms
7,864 KB
testcase_27 AC 183 ms
7,804 KB
testcase_28 AC 185 ms
7,832 KB
testcase_29 AC 186 ms
7,624 KB
testcase_30 AC 181 ms
7,860 KB
testcase_31 AC 185 ms
7,720 KB
testcase_32 WA -
testcase_33 AC 189 ms
7,872 KB
testcase_34 WA -
testcase_35 AC 185 ms
7,624 KB
testcase_36 AC 185 ms
7,860 KB
testcase_37 AC 184 ms
7,632 KB
testcase_38 AC 183 ms
7,636 KB
testcase_39 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(v) v.begin(), v.end()
typedef long long ll;

#include <bits/stdc++.h>
using namespace std;

template<typename T>
vector<T> smallest_prime_factors(T n){
  vector<T> spf(n+1);
  for(int i=0;i<=n;i++) spf[i]=i;

  for(T i=2;i*i<=n;i++){
    if(spf[i]==i){ //素数だったら
      for(T j=i*i;j<=n;j+=i){ 
        if(spf[j]==j) spf[j]=i; //iを持つ整数かつまだ素数が決まっていないなら
      }
    }
  }
  return spf;
}

//高速因数分解(クエリ<=10^5,整数<=10^6程度)
template<typename T>
bool factolization(T x,vector<T> &spf){
  int cnt=0;
  while(x!=1) {
    x/=spf[x];
    cnt++;
    if(cnt>=3){
      break;
    }
  }
  if(cnt>=3) return true;
  return false;
}

int main(){
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  
  constexpr int MAX=400040; 
  auto spf=smallest_prime_factors(MAX);
  
  vector<int> A(MAX+1);
  for(int i=1;i<MAX;i++){
    if(factolization(i,spf)==1) A[i]=1;
  }
  
  //素数の3乗
  for(int i=1;i*i*i<MAX;i++){
    if(spf[i]==i) A[i*i*i]=0;
  }
  
  vector<int> S(MAX+2);
  for(int i=1;i<MAX;i++) S[i]=A[i]+S[i-1];
  
  int t;
  cin>>t;
  while(t--){
    ll p,l,r;
    cin>>p>>l>>r;
    
    l-=p,r-=p;
    
    if(l>0 && r>0) cout<<S[r]-S[l-1]<<endl;
    else if(l<0 && r<0) cout<<S[-l]-S[-r-1]<<endl;
    else if(l==0 && r==0) cout<<1<<endl;
    else if(l==0) cout<<1+S[r]<<endl;
    else if(r==0) cout<<1+S[-1]<<endl;
    else cout<<1+S[r]+S[-l]<<endl;
  }
  
  return 0;
}
0