結果

問題 No.673 カブトムシ
ユーザー bal4ubal4u
提出日時 2019-05-02 14:29:36
言語 C
(gcc 12.3.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 836 bytes
コンパイル時間 801 ms
コンパイル使用メモリ 29,192 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-14 16:13:58
合計ジャッジ時間 1,614 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

// yukicoder: No.673 カブトムシ
// 2019.5.2 bal4u

#include <stdio.h>

#define M 1000000007

long long extended_gcd(long long a, long long b, long long *x, long long *y)
{
	long long d;

	if (b == 0) { *x = 1; *y = 0; return a; }
	d = extended_gcd(b, a % b, y, x);
	*y -= a / b * (*x);
	return d;
}

int inverse(long long a)
{
    long long x, y;
    extended_gcd(a, (long long)M, &x, &y);
	return (int)((x + M) % M);
}

int bigPow(long long x, long long p)
{
	long long r = 1;
	while (p) {
		if (p & 1) r = r * x % M;
		x = x * x % M;
		p >>= 1;
	}
	return (int)r;
}


int main()
{
	long long B, C, D, ans;
	
	scanf("%lld%lld%lld", &B, &C, &D);
	if (C == 1) ans = (B % M) * (D % M);
	else {
		ans = ((B % M) * (C % M)) % M;
		ans = (ans * ((M+bigPow(C % M, D)-1) % M)) % M * inverse(C-1);
	}
	printf("%d\n", ans % M);
	return 0;
}
0