結果

問題 No.1177 余りは?
ユーザー kotatsugame
提出日時 2020-08-21 23:12:37
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 32 ms / 1,000 ms
コード長 452 bytes
コンパイル時間 510 ms
コンパイル使用メモリ 66,212 KB
実行使用メモリ 15,232 KB
最終ジャッジ日時 2024-10-15 06:33:03
合計ジャッジ時間 1,835 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 32
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:8:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
    8 | main()
      | ^~~~

ソースコード

diff #

#include<iostream>
using namespace std;
long P,K;
const long mod=1e9+7;
long dp[1<<20];
int ex[1<<20];
long power(long a,long b){return b?power(a*a%mod,b/2)*(b%2?a:1)%mod:1;}
main()
{
	cin>>P>>K;
	long ans=0;
	long now=1;
	int turn=0;
	while(!ex[now])
	{
		++turn;
		ex[now]=turn;
		dp[now]=ans;
		now=now*10;
		ans=(ans*10+now/P)%mod;
		now%=P;
	}
	ans=(ans-dp[now]*power(10,turn-ex[now]+1)%mod+mod)%mod;
	if(K==0)ans=(ans+1)%mod;
	cout<<ans<<endl;
}
0