結果

問題 No.673 カブトムシ
ユーザー snrnsidysnrnsidy
提出日時 2021-12-11 03:24:18
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 800 bytes
コンパイル時間 3,545 ms
コンパイル使用メモリ 197,412 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-26 07:35:09
合計ジャッジ時間 3,253 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
 
using namespace std;

long long int a,r,n,mod;

long long int mypow(long long int x,long long int n)
{
	long long int res = 1;
	while(n>0)
	{
		if(n%2==1)
		{
			res = (x%mod) * (res%mod);
			res%=mod;
		}
		x = (x%mod) * (x%mod);
		x%=mod;
		n/=2;
	}

	return res;
}
long long int func(long long int n)
{
	if(n==1)
	{
		return r%mod;
	}

	if(n%2==0)
	{
		long long int x = (mypow(r,n/2)%mod + (1%mod))%mod;
		x%=mod;
		return ((x%mod)*(func(n/2)%mod))%mod;
	}
	else
	{
		return ((r%mod)*((func(n-1)%mod)) + r%mod)%mod;
	}
}
int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);

	cin >> a >> r >> n;

  mod = 1e9 + 7;

	if(n==1)
	{
		cout << (a*r)%mod << '\n';
		return 0;
	}
	cout << ((((a%mod)*((func(n-1)%mod + 1%mod)%mod)%mod)*(r%mod))%mod) << '\n';
	return 0;
}
0