結果

問題 No.1411 Hundreds of Conditions Sequences
ユーザー 👑 NachiaNachia
提出日時 2021-02-26 22:05:12
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 110 ms / 2,000 ms
コード長 2,414 bytes
コンパイル時間 2,610 ms
コンパイル使用メモリ 205,536 KB
実行使用メモリ 23,364 KB
最終ジャッジ日時 2024-04-10 12:48:47
合計ジャッジ時間 11,090 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 14 ms
17,920 KB
testcase_01 AC 14 ms
17,792 KB
testcase_02 AC 14 ms
17,792 KB
testcase_03 AC 14 ms
17,792 KB
testcase_04 AC 14 ms
17,792 KB
testcase_05 AC 13 ms
17,920 KB
testcase_06 AC 13 ms
17,920 KB
testcase_07 AC 14 ms
17,792 KB
testcase_08 AC 13 ms
17,920 KB
testcase_09 AC 15 ms
17,920 KB
testcase_10 AC 14 ms
17,792 KB
testcase_11 AC 14 ms
17,920 KB
testcase_12 AC 91 ms
22,656 KB
testcase_13 AC 70 ms
21,376 KB
testcase_14 AC 42 ms
19,584 KB
testcase_15 AC 69 ms
21,248 KB
testcase_16 AC 18 ms
18,176 KB
testcase_17 AC 66 ms
21,248 KB
testcase_18 AC 87 ms
22,400 KB
testcase_19 AC 97 ms
22,980 KB
testcase_20 AC 43 ms
19,584 KB
testcase_21 AC 102 ms
23,236 KB
testcase_22 AC 47 ms
19,712 KB
testcase_23 AC 93 ms
22,596 KB
testcase_24 AC 14 ms
17,920 KB
testcase_25 AC 91 ms
22,400 KB
testcase_26 AC 68 ms
20,992 KB
testcase_27 AC 43 ms
19,712 KB
testcase_28 AC 78 ms
21,760 KB
testcase_29 AC 22 ms
18,304 KB
testcase_30 AC 60 ms
20,736 KB
testcase_31 AC 58 ms
20,352 KB
testcase_32 AC 107 ms
23,236 KB
testcase_33 AC 102 ms
23,236 KB
testcase_34 AC 102 ms
23,112 KB
testcase_35 AC 104 ms
23,168 KB
testcase_36 AC 104 ms
23,296 KB
testcase_37 AC 102 ms
23,296 KB
testcase_38 AC 105 ms
23,168 KB
testcase_39 AC 102 ms
23,168 KB
testcase_40 AC 103 ms
23,236 KB
testcase_41 AC 104 ms
23,232 KB
testcase_42 AC 107 ms
23,168 KB
testcase_43 AC 105 ms
23,168 KB
testcase_44 AC 104 ms
23,240 KB
testcase_45 AC 104 ms
23,108 KB
testcase_46 AC 104 ms
23,040 KB
testcase_47 AC 104 ms
23,168 KB
testcase_48 AC 103 ms
23,168 KB
testcase_49 AC 110 ms
23,168 KB
testcase_50 AC 109 ms
23,364 KB
testcase_51 AC 103 ms
23,104 KB
testcase_52 AC 102 ms
23,108 KB
testcase_53 AC 102 ms
23,112 KB
testcase_54 AC 103 ms
23,236 KB
testcase_55 AC 101 ms
23,296 KB
testcase_56 AC 102 ms
23,240 KB
testcase_57 AC 102 ms
23,364 KB
testcase_58 AC 102 ms
23,168 KB
testcase_59 AC 103 ms
23,296 KB
testcase_60 AC 102 ms
23,240 KB
testcase_61 AC 104 ms
23,236 KB
testcase_62 AC 80 ms
22,212 KB
testcase_63 AC 84 ms
22,144 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using LL=long long;
using ULL=unsigned long long;
#define rep(i,n) for(int i=0; i<(n); i++)

int sieve[1000001]={};

struct Factors{
  vector<pair<int,int>> V;
  Factors(int A=1){
    while(A!=1){
      int p=sieve[A];
      V.push_back({p,0});
      while(A%p==0){ V.back().second++; A/=p; }
    }
    sort(V.begin(),V.end());
  }
  Factors(vector<pair<int,int>> v) : V(move(v)) {}
  int size() const { return V.size(); }
  pair<int,int>& operator[](int i) { return V[i]; }
  const pair<int,int>& operator[](int i) const{ return V[i]; }
};

Factors lcm(const Factors& l,const Factors& r){
  int il=0, ir=0;
  vector<pair<int,int>> V;
  while(il+ir<l.size()+r.size()){
    bool usel;
    if(il==l.size()) usel=false;
    else if(ir==r.size()) usel=true;
    else usel=l[il].first<r[ir].first;
    bool tomerge=false;
    pair<int,int> f=(usel?l[il++]:r[ir++]);
    if(V.size()) if(V.back().first==f.first) tomerge=true;
    if(tomerge) V.back().second+=f.second;
    else V.push_back(f);
  }
  return move(V);
}

ULL modval(const Factors& v,ULL m){
  ULL res=1;
  for(auto f:v.V) rep(t,f.second) res=res*f.first%m;
  return res;
}

const ULL M=1000000007;
ULL powm(ULL a,ULL i){
  if(i==0) return 1;
  ULL r=powm(a*a%M,i/2);
  if(i%2==1) r=r*a%M;
  return r;
}
ULL invm(ULL a){ return powm(a,M-2); }

int N;
int A[100000];
ULL allprod;
ULL alllcm;
ULL ans[100000];
int P[1000001][2];
Factors F[100000];

int main(){
  sieve[0]=sieve[1]=1;
  for(int i=2; i<=1000000; i++){
    if(sieve[i]!=0) continue;
    sieve[i]=i;
    if(i<=1000) for(int j=i*i; j<=1000000; j+=i) sieve[j]=i;
  }

  rep(i,1000001) P[i][0]=0;

  scanf("%d",&N);
  rep(i,N) scanf("%d",&A[i]);

  rep(i,N){
    F[i]=Factors(A[i]);
    for(auto f:F[i].V){
      if(P[f.first][1]<f.second) P[f.first][1]=f.second;
      if(P[f.first][0]<P[f.first][1]) swap(P[f.first][0],P[f.first][1]);
    }
  }

  rep(i,N){
    ans[i]=1;
    for(auto f:F[i].V){
      if(P[f.first][0]==f.second) ans[i]=ans[i]*powm(f.first,P[f.first][0]-P[f.first][1])%M;
      //printf("p=%d : (%d,%d)\n",f.first,P[f.first][0],P[f.first][1]);
    }
  }

  allprod=1; rep(i,N) allprod=allprod*A[i]%M;
  alllcm=1; rep(i,1000001) if(P[i][0]!=0) alllcm=alllcm*powm(i,P[i][0])%M;
  rep(i,N) ans[i]=alllcm*invm(ans[i])%M;
  rep(i,N) ans[i]=(allprod*invm(A[i])%M+M-ans[i])%M;
  rep(i,N) printf("%u\n",(unsigned int)ans[i]);

  return 0;
}
0