結果

問題 No.1567 Integer Coefficient Equation
ユーザー umezoumezo
提出日時 2021-06-26 14:31:18
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 187 ms / 2,000 ms
コード長 1,514 bytes
コンパイル時間 2,892 ms
コンパイル使用メモリ 200,792 KB
実行使用メモリ 7,896 KB
最終ジャッジ日時 2023-09-07 16:40:52
合計ジャッジ時間 9,935 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 14 ms
7,652 KB
testcase_01 AC 15 ms
7,752 KB
testcase_02 AC 167 ms
7,608 KB
testcase_03 AC 164 ms
7,724 KB
testcase_04 AC 163 ms
7,656 KB
testcase_05 AC 163 ms
7,836 KB
testcase_06 AC 164 ms
7,604 KB
testcase_07 AC 16 ms
7,636 KB
testcase_08 AC 15 ms
7,740 KB
testcase_09 AC 16 ms
7,840 KB
testcase_10 AC 14 ms
7,656 KB
testcase_11 AC 15 ms
7,656 KB
testcase_12 AC 14 ms
7,640 KB
testcase_13 AC 14 ms
7,844 KB
testcase_14 AC 15 ms
7,600 KB
testcase_15 AC 15 ms
7,716 KB
testcase_16 AC 15 ms
7,892 KB
testcase_17 AC 179 ms
7,640 KB
testcase_18 AC 179 ms
7,608 KB
testcase_19 AC 182 ms
7,792 KB
testcase_20 AC 181 ms
7,636 KB
testcase_21 AC 180 ms
7,896 KB
testcase_22 AC 180 ms
7,692 KB
testcase_23 AC 181 ms
7,604 KB
testcase_24 AC 183 ms
7,800 KB
testcase_25 AC 184 ms
7,692 KB
testcase_26 AC 178 ms
7,796 KB
testcase_27 AC 185 ms
7,852 KB
testcase_28 AC 184 ms
7,636 KB
testcase_29 AC 180 ms
7,744 KB
testcase_30 AC 182 ms
7,836 KB
testcase_31 AC 182 ms
7,636 KB
testcase_32 AC 186 ms
7,640 KB
testcase_33 AC 187 ms
7,796 KB
testcase_34 AC 185 ms
7,748 KB
testcase_35 AC 179 ms
7,740 KB
testcase_36 AC 181 ms
7,836 KB
testcase_37 AC 183 ms
7,788 KB
testcase_38 AC 182 ms
7,688 KB
testcase_39 AC 174 ms
7,744 KB
権限があれば一括ダウンロードができます

ソースコード

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[-l]<<endl;
    else cout<<1+S[r]+S[-l]<<endl;
  }
  
  return 0;
}
0