結果
| 問題 | No.1092 modular arithmetic |
| ユーザー |
|
| 提出日時 | 2020-07-05 13:27:01 |
| 言語 | C++14 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 121 ms / 2,000 ms |
| コード長 | 703 bytes |
| 記録 | |
| コンパイル時間 | 627 ms |
| コンパイル使用メモリ | 65,708 KB |
| 実行使用メモリ | 6,944 KB |
| 最終ジャッジ日時 | 2024-09-22 10:08:39 |
| 合計ジャッジ時間 | 4,605 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 32 |
ソースコード
#include<iostream>
using namespace std;
typedef long long ll;
ll modpow(ll a, ll b, ll p = 1e9+7){
if(b == 0) return 1;
if(b % 2 == 0){
ll d = modpow(a, b/2, p);
return (d*d) % p;
}else{
return (a%p * modpow(a, b-1, p)) % p;
}
}
int main(){
int p, n;
cin >> p >> n;
int a[n];
for(int i = 0; i < n; i++) cin >> a[i];
ll ans = a[0];
for(int i = 1; i < n; i++){
char c;
cin >> c;
if(c == '+') (ans += a[i]) %= p;
if(c == '-') (ans += p-a[i]) %= p;
if(c == '*') (ans *= a[i]) %= p;
if(c == '/') (ans *= modpow(a[i], p-2, p)) %= p;
}
cout << ans << endl;
return 0;
}