結果

問題 No.1411 Hundreds of Conditions Sequences
ユーザー 沙耶花沙耶花
提出日時 2021-02-27 00:12:33
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 223 ms / 2,000 ms
コード長 1,274 bytes
コンパイル時間 4,597 ms
コンパイル使用メモリ 262,140 KB
実行使用メモリ 16,528 KB
最終ジャッジ日時 2024-04-10 14:51:01
合計ジャッジ時間 17,905 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 22 ms
15,632 KB
testcase_01 AC 21 ms
15,664 KB
testcase_02 AC 21 ms
15,628 KB
testcase_03 AC 21 ms
15,632 KB
testcase_04 AC 22 ms
15,556 KB
testcase_05 AC 22 ms
15,476 KB
testcase_06 AC 22 ms
15,468 KB
testcase_07 AC 21 ms
15,436 KB
testcase_08 AC 23 ms
15,632 KB
testcase_09 AC 23 ms
15,504 KB
testcase_10 AC 22 ms
15,624 KB
testcase_11 AC 22 ms
15,608 KB
testcase_12 AC 184 ms
16,140 KB
testcase_13 AC 140 ms
15,960 KB
testcase_14 AC 85 ms
15,712 KB
testcase_15 AC 138 ms
15,992 KB
testcase_16 AC 29 ms
15,480 KB
testcase_17 AC 130 ms
15,904 KB
testcase_18 AC 183 ms
16,188 KB
testcase_19 AC 200 ms
16,268 KB
testcase_20 AC 85 ms
15,712 KB
testcase_21 AC 207 ms
16,348 KB
testcase_22 AC 92 ms
15,628 KB
testcase_23 AC 183 ms
16,136 KB
testcase_24 AC 22 ms
15,672 KB
testcase_25 AC 187 ms
16,268 KB
testcase_26 AC 135 ms
15,960 KB
testcase_27 AC 87 ms
15,676 KB
testcase_28 AC 159 ms
16,140 KB
testcase_29 AC 44 ms
15,616 KB
testcase_30 AC 125 ms
15,808 KB
testcase_31 AC 114 ms
15,904 KB
testcase_32 AC 217 ms
16,424 KB
testcase_33 AC 207 ms
16,256 KB
testcase_34 AC 203 ms
16,396 KB
testcase_35 AC 200 ms
16,392 KB
testcase_36 AC 214 ms
16,396 KB
testcase_37 AC 200 ms
16,376 KB
testcase_38 AC 207 ms
16,268 KB
testcase_39 AC 205 ms
16,392 KB
testcase_40 AC 219 ms
16,264 KB
testcase_41 AC 203 ms
16,396 KB
testcase_42 AC 204 ms
16,280 KB
testcase_43 AC 204 ms
16,248 KB
testcase_44 AC 210 ms
16,396 KB
testcase_45 AC 206 ms
16,268 KB
testcase_46 AC 207 ms
16,388 KB
testcase_47 AC 208 ms
16,268 KB
testcase_48 AC 223 ms
16,396 KB
testcase_49 AC 212 ms
16,268 KB
testcase_50 AC 209 ms
16,528 KB
testcase_51 AC 211 ms
16,252 KB
testcase_52 AC 210 ms
16,376 KB
testcase_53 AC 210 ms
16,268 KB
testcase_54 AC 204 ms
16,212 KB
testcase_55 AC 200 ms
16,396 KB
testcase_56 AC 207 ms
16,528 KB
testcase_57 AC 208 ms
16,244 KB
testcase_58 AC 209 ms
16,344 KB
testcase_59 AC 208 ms
16,392 KB
testcase_60 AC 208 ms
16,336 KB
testcase_61 AC 207 ms
16,360 KB
testcase_62 AC 189 ms
16,400 KB
testcase_63 AC 189 ms
16,268 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <atcoder/all>
#include <bits/stdc++.h>
using namespace std;
using namespace atcoder;
using mint = modint1000000007;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf 1000000001


int main(){
	
	vector<int> isp(1000001,-1);
	vector<int> p;
	for(int i=2;i<isp.size();i++){
		if(isp[i]==-1){
			p.push_back(i);
			for(int j=i;j<isp.size();j+=i)isp[j] = i;
		}
	}
	int N;
	cin>>N;
	vector<int> A(N);
	mint sum = 1;
	vector<int> cnt(1000001,0);
	rep(i,N){
		scanf("%d",&A[i]);
		cnt[A[i]]++;
		sum *= A[i];
	}
	vector<int> cnt2(1000001,0);
	rep(i,p.size()){
		long long cur = p[i];
		while(cur <= 1000000){
			
			for(int j=cur;j<=1000000;j+=cur){
				cnt2[cur] += cnt[j];
			}
			if(cnt2[cur]>=2){
				sum /= mint(p[i]).pow(cnt2[cur]-1);
			}
			cur *= p[i];
		}
	}
	vector<mint> ans(N,0);
	//cout<<sum.val()<<endl;
	rep(i,N){
		mint temp = sum / A[i];
		map<int,int> mp;
		int t = A[i];
		while(t!=1){
			mp[isp[t]]++;
			t/=isp[t];
		}
		for(auto a:mp){
			int x = 1;
			rep(j,a.second){
				x *= a.first;
				if(cnt2[x]>=2){
					temp *= a.first;
				}
			}
		}
		ans[i] = temp;
	}
	
	sum = 1;
	rep(i,N){
		sum *= A[i];
	}
	
	rep(i,N){
		ans[i] = sum / A[i] - ans[i];
	}
	
	rep(i,N){
		cout<<ans[i].val()<<endl;
	}
	
	
		
    return 0;
}
0