結果

問題 No.1580 I like Logarithm!
ユーザー 37zigen
提出日時 2021-07-03 01:24:07
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 33 ms / 2,000 ms
コード長 575 bytes
コンパイル時間 478 ms
コンパイル使用メモリ 62,912 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-06-29 17:38:39
合計ジャッジ時間 2,322 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 6
other AC * 39
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<vector>
#include<list>
typedef long long ll;

using namespace std;
const ll p=(ll) 1e9+7;

ll powmod(ll a, ll n) {
		return n==0?1:powmod(a*a%p,n/2)*(n%2==1?a:1)%p;
}

ll tolong(string B, ll A) {
		ll x=0;
		for (int i=0;i<B.size();++i) {
				x=x*A%p;
				x+=B[i]-'0';
		}
		return x;
}

int main() {
		long long x = 0;
		int A;
		string B;
		cin >> A;
		cin >> B;
		int n=B.size();
		ll upper=(tolong(B,A)+1)%p;
		for (int i=1;i<=n;++i) {
				x+= ((i==n?upper:powmod(A, i)) - powmod(A, i-1) + p) * (i-1) % p;
				x%=p;
		}
		cout << x << endl;
}
0