結果

問題 No.1411 Hundreds of Conditions Sequences
ユーザー 👑 NachiaNachia
提出日時 2021-02-26 22:05:12
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 123 ms / 2,000 ms
コード長 2,414 bytes
コンパイル時間 2,101 ms
コンパイル使用メモリ 204,416 KB
最終ジャッジ日時 2025-01-19 05:30:15
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 62
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:76:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   76 |   scanf("%d",&N);
      |   ~~~~~^~~~~~~~~
main.cpp:77:17: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   77 |   rep(i,N) scanf("%d",&A[i]);
      |            ~~~~~^~~~~~~~~~~~

ソースコード

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;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0