結果

問題 No.492 IOI数列
ユーザー startcppstartcpp
提出日時 2017-03-11 18:56:12
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 786 bytes
コンパイル時間 1,051 ms
コンパイル使用メモリ 52,172 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-06 18:10:33
合計ジャッジ時間 1,407 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,376 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 2 ms
4,376 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 1 ms
4,376 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 1 ms
4,376 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 1 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

//a_N = 1 + 100 + 100^2 + … + 100^(N-1) = (100^N - 1) / 99
//10^9 + 7で割った余り…フェルマーの小定理より(100^N - 1) * 99^(10^9 + 5) % (10^9 + 7)と値が一致
//a_11で割った余り…N % 11 == 0のとき0より、a_N % a_11 = a_(N % 11)

#include <iostream>
#define int long long
using namespace std;

int powmod(int a, int n, int mod) {
	if (n == 0) return 1;
	if (n % 2 == 0) return powmod((a * a) % mod, n / 2, mod) % mod;
	return (a * powmod(a, n - 1, mod)) % mod;
}

signed main() {
	int n;
	cin >> n;
	
	int p = 1000000007;
	int a = (powmod(100, n, p) + p - 1) % p;
	int b = powmod(99, p - 2, p);
	cout << (a * b) % p << endl;
	
	int ans = 0, add = 1;
	for (int i = 0; i < n % 11; i++) {
		ans += add;
		add *= 100;
	}
	cout << ans << endl;
	
	return 0;
}
0