結果

問題 No.1411 Hundreds of Conditions Sequences
ユーザー snow39snow39
提出日時 2021-02-27 10:59:25
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 1,022 ms / 2,000 ms
コード長 2,207 bytes
コンパイル時間 1,326 ms
コンパイル使用メモリ 121,560 KB
実行使用メモリ 79,416 KB
最終ジャッジ日時 2024-04-10 15:26:35
合計ジャッジ時間 21,725 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
外部呼び出し有り
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 22 ms
50,080 KB
testcase_01 AC 22 ms
50,096 KB
testcase_02 AC 22 ms
50,100 KB
testcase_03 AC 22 ms
50,136 KB
testcase_04 AC 23 ms
50,072 KB
testcase_05 AC 22 ms
50,212 KB
testcase_06 AC 23 ms
50,128 KB
testcase_07 AC 22 ms
50,136 KB
testcase_08 AC 24 ms
50,160 KB
testcase_09 AC 23 ms
50,112 KB
testcase_10 AC 21 ms
50,160 KB
testcase_11 AC 22 ms
50,152 KB
testcase_12 AC 296 ms
74,588 KB
testcase_13 AC 222 ms
68,160 KB
testcase_14 AC 123 ms
59,424 KB
testcase_15 AC 220 ms
67,980 KB
testcase_16 AC 35 ms
51,204 KB
testcase_17 AC 217 ms
67,136 KB
testcase_18 AC 299 ms
74,360 KB
testcase_19 AC 324 ms
76,708 KB
testcase_20 AC 126 ms
59,456 KB
testcase_21 AC 350 ms
78,432 KB
testcase_22 AC 136 ms
60,620 KB
testcase_23 AC 305 ms
74,968 KB
testcase_24 AC 22 ms
50,168 KB
testcase_25 AC 294 ms
74,296 KB
testcase_26 AC 212 ms
67,372 KB
testcase_27 AC 127 ms
59,940 KB
testcase_28 AC 248 ms
70,364 KB
testcase_29 AC 48 ms
52,596 KB
testcase_30 AC 188 ms
64,896 KB
testcase_31 AC 171 ms
63,836 KB
testcase_32 AC 357 ms
78,708 KB
testcase_33 AC 351 ms
78,664 KB
testcase_34 AC 355 ms
78,728 KB
testcase_35 AC 350 ms
78,596 KB
testcase_36 AC 360 ms
78,644 KB
testcase_37 AC 352 ms
78,652 KB
testcase_38 AC 354 ms
78,732 KB
testcase_39 AC 363 ms
78,748 KB
testcase_40 AC 351 ms
78,608 KB
testcase_41 AC 353 ms
78,664 KB
testcase_42 AC 372 ms
78,652 KB
testcase_43 AC 350 ms
78,628 KB
testcase_44 AC 346 ms
78,656 KB
testcase_45 AC 351 ms
78,596 KB
testcase_46 AC 366 ms
78,776 KB
testcase_47 AC 351 ms
78,668 KB
testcase_48 AC 352 ms
78,716 KB
testcase_49 AC 354 ms
78,712 KB
testcase_50 AC 356 ms
78,740 KB
testcase_51 AC 347 ms
78,772 KB
testcase_52 AC 416 ms
79,348 KB
testcase_53 AC 421 ms
79,416 KB
testcase_54 AC 422 ms
79,204 KB
testcase_55 AC 425 ms
79,240 KB
testcase_56 AC 421 ms
79,388 KB
testcase_57 AC 425 ms
79,304 KB
testcase_58 AC 424 ms
79,268 KB
testcase_59 AC 422 ms
79,340 KB
testcase_60 AC 419 ms
79,308 KB
testcase_61 AC 421 ms
79,272 KB
testcase_62 AC 1,022 ms
63,368 KB
testcase_63 AC 579 ms
65,036 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
}
0