結果

問題 No.1411 Hundreds of Conditions Sequences
ユーザー 👑 ygussanyygussany
提出日時 2021-02-26 23:33:59
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 658 ms / 2,000 ms
コード長 1,464 bytes
コンパイル時間 422 ms
コンパイル使用メモリ 33,460 KB
実行使用メモリ 7,168 KB
最終ジャッジ日時 2024-04-10 14:43:09
合計ジャッジ時間 13,121 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 6 ms
6,816 KB
testcase_01 AC 6 ms
6,944 KB
testcase_02 AC 7 ms
6,940 KB
testcase_03 AC 7 ms
6,940 KB
testcase_04 AC 7 ms
6,940 KB
testcase_05 AC 7 ms
6,940 KB
testcase_06 AC 6 ms
6,944 KB
testcase_07 AC 5 ms
6,944 KB
testcase_08 AC 6 ms
7,032 KB
testcase_09 AC 7 ms
6,944 KB
testcase_10 AC 6 ms
6,944 KB
testcase_11 AC 6 ms
6,940 KB
testcase_12 AC 161 ms
7,100 KB
testcase_13 AC 130 ms
6,948 KB
testcase_14 AC 66 ms
6,944 KB
testcase_15 AC 124 ms
6,948 KB
testcase_16 AC 14 ms
6,944 KB
testcase_17 AC 120 ms
6,944 KB
testcase_18 AC 161 ms
6,980 KB
testcase_19 AC 178 ms
7,136 KB
testcase_20 AC 67 ms
6,944 KB
testcase_21 AC 187 ms
7,168 KB
testcase_22 AC 73 ms
6,940 KB
testcase_23 AC 163 ms
7,064 KB
testcase_24 AC 7 ms
6,944 KB
testcase_25 AC 163 ms
7,108 KB
testcase_26 AC 116 ms
7,008 KB
testcase_27 AC 68 ms
7,036 KB
testcase_28 AC 141 ms
7,052 KB
testcase_29 AC 22 ms
6,940 KB
testcase_30 AC 103 ms
6,976 KB
testcase_31 AC 95 ms
6,940 KB
testcase_32 AC 191 ms
6,972 KB
testcase_33 AC 192 ms
7,164 KB
testcase_34 AC 195 ms
7,144 KB
testcase_35 AC 193 ms
7,104 KB
testcase_36 AC 192 ms
7,164 KB
testcase_37 AC 188 ms
7,088 KB
testcase_38 AC 192 ms
7,132 KB
testcase_39 AC 194 ms
7,072 KB
testcase_40 AC 186 ms
7,164 KB
testcase_41 AC 190 ms
7,164 KB
testcase_42 AC 193 ms
7,168 KB
testcase_43 AC 193 ms
7,132 KB
testcase_44 AC 189 ms
7,048 KB
testcase_45 AC 190 ms
7,140 KB
testcase_46 AC 190 ms
7,088 KB
testcase_47 AC 201 ms
7,076 KB
testcase_48 AC 195 ms
6,948 KB
testcase_49 AC 192 ms
7,136 KB
testcase_50 AC 192 ms
7,156 KB
testcase_51 AC 197 ms
7,160 KB
testcase_52 AC 239 ms
7,044 KB
testcase_53 AC 244 ms
7,168 KB
testcase_54 AC 237 ms
7,160 KB
testcase_55 AC 236 ms
7,144 KB
testcase_56 AC 241 ms
7,068 KB
testcase_57 AC 237 ms
7,124 KB
testcase_58 AC 241 ms
6,948 KB
testcase_59 AC 238 ms
7,076 KB
testcase_60 AC 236 ms
7,092 KB
testcase_61 AC 239 ms
7,160 KB
testcase_62 AC 658 ms
7,128 KB
testcase_63 AC 393 ms
6,968 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>

const int Mod = 1000000007;

long long div_mod(long long x, long long y, long long z)
{
	if (x % y == 0) return x / y;
	else return (div_mod((1 + x / y) * y - x, (z % y), y) * z + x) / y;
}

long long pow_mod(long long n, int k)
{
	long long N, ans = 1;
	for (N = n; k > 0; k >>= 1, N = N * N % Mod) if (k & 1) ans = ans * N % Mod;
	return ans;
}

int main()
{
	int i, N, A[100001];
	scanf("%d", &N);
	for (i = 1; i <= N; i++) scanf("%d", &(A[i]));
	
	int h, j, k, l, m, count[1000001] = {};
	long long total[2] = {1, 1}, tmp;
	for (i = 1; i <= N; i++) {
		total[0] = total[0] * A[i] % Mod;
		if (A[i] == 1) continue;
		for (j = 2, m = A[i]; j * j <= m; j++) {
			if (m % j != 0) continue;
			for (k = 0, l = j; m % j == 0; k++, l *= j) {
				count[l]++;
				m /= j;
			}
		}
		if (m > 1) count[m]++;
	}
	
	char flag[1000001] = {};
	for (i = 2; i <= 1000000; i++) {
		if (flag[i] != 0) continue;
		for (j = i * 2; j <= 1000000; j += i) flag[j] = 1;
		for (tmp = i; tmp <= 1000000; tmp *= i) total[1] = total[1] * div_mod(1, pow_mod(i, (count[tmp] - 1)), Mod) % Mod;
	}
	
	for (i = 1; i <= N; i++) {
		for (j = 2, tmp = 1, m = A[i]; j * j <= m; j++) {
			if (m % j != 0) continue;
			for (k = 0, l = j; m % j == 0; k++, l *= j) {
				if (count[l] > 1) tmp *= j;
				m /= j;
			}
		}
		if (m > 1 && count[m] > 1) tmp *= m;
		printf("%lld\n", div_mod(total[0], A[i], Mod) * (1 - total[1] * tmp % Mod + Mod) % Mod);
	}
	fflush(stdout);
	return 0;
}
0