結果
問題 |
No.1411 Hundreds of Conditions Sequences
|
ユーザー |
![]() |
提出日時 | 2021-02-27 10:59:25 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 1,186 ms / 2,000 ms |
コード長 | 2,207 bytes |
コンパイル時間 | 1,274 ms |
コンパイル使用メモリ | 117,036 KB |
最終ジャッジ日時 | 2025-01-19 07:46:35 |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 62 |
ソースコード
#include <iostream> #include <algorithm> #include <string> #include <vector> #include <cmath> #include <map> #include <queue> #include <iomanip> #include <set> #include <tuple> #define mkp make_pair #define mkt make_tuple #define rep(i,n) for(int i = 0; i < (n); ++i) #define all(v) v.begin(),v.end() using namespace std; typedef long long ll; const ll MOD=1e9+7; template<class T> void chmin(T &a,const T &b){if(a>b) a=b;} template<class T> void chmax(T &a,const T &b){if(a<b) a=b;} ll mod_pow(ll x,ll n){ x%=MOD; ll res=1; while(n>0){ if(n&1) res=res*x%MOD; x=x*x%MOD; n>>=1; } return res; } ll mod_inverse(ll x){ return mod_pow(x,MOD-2); } void add(ll &a,ll b){ a=(a+b)%MOD; } void mul(ll &a,ll b){ a%=MOD;b%=MOD; a=a*b%MOD; } vector<pair<ll,int>> factorize(ll x){ vector<pair<ll,int>> res; for(ll i=2;i*i<=x;i++){ int num=0; while(x%i==0){ x/=i; num++; } if(num) res.push_back(mkp(i,num)); } if(x!=1) res.push_back(mkp(x,1)); return res; } const int L=1e6; int main(){ cin.tie(0); ios::sync_with_stdio(false); int N; cin>>N; vector<ll> A(N); rep(i,N) cin>>A[i]; vector<vector<pair<ll,int>>> primes(N); rep(i,N) primes[i]=factorize(A[i]); vector<set<pair<ll,int>>> vse(L+1); rep(i,N){ for(auto [p,num]:primes[i]){ vse[p].insert(mkp(num,i)); } } ll all=1; for(int p=1;p<=L;p++){ if(vse[p].empty()) continue; auto itr=vse[p].end(); itr--; auto [num,tar]=*itr; ll factor=mod_pow(p,num); mul(all,factor); } vector<ll> ans(N,all); for(int p=1;p<=L;p++){ if(vse[p].empty()) continue; auto itr=vse[p].end(); itr--; auto [num,tar]=*itr; ll factor=mod_pow(p,num); ll nex_factor=1; if(itr!=vse[p].begin()){ itr--; int nex_num=(*itr).first; nex_factor=mod_pow(p,nex_num); } mul(ans[tar],mod_inverse(factor/nex_factor)); } ll sum_mult=1; rep(i,N) mul(sum_mult,A[i]); rep(i,N){ ans[i]=(sum_mult*mod_inverse(A[i])%MOD-ans[i]+MOD)%MOD; add(ans[i],MOD); } rep(i,N) cout<<ans[i]<<"\n"; return 0; }