結果
問題 |
No.1092 modular arithmetic
|
ユーザー |
![]() |
提出日時 | 2020-07-27 20:48:06 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 106 ms / 2,000 ms |
コード長 | 870 bytes |
コンパイル時間 | 1,522 ms |
コンパイル使用メモリ | 166,092 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-06-28 20:13:56 |
合計ジャッジ時間 | 4,187 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 32 |
ソースコード
#include <bits/stdc++.h> #define rep(i, n) for(int i= 0; i < (n); i++) using ll= long long int; using namespace std; template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } ll mod= 1e9 + 7; ll RepeatSquaring(ll N, ll P, ll M){ if(P==0) return 1; if(P%2==0){ ll t = RepeatSquaring(N, P/2, M); return t*t % M; } return N * RepeatSquaring(N, P-1, M)%M; } int main(){ ll p,n; cin >> p >> n; ll a[n]; rep(i,n)cin >> a[i]; ll ans=a[0]; for(int i=1;i<n;i++){ char g; cin >> g; if(g=='+'){ans+=a[i];} else if(g=='-'){ans-=a[i];} else if(g=='*'){ans*=(a[i]%p);} else if(g=='/'){ans*=RepeatSquaring(a[i],p-2,p);} ans%=p; while(ans<0)ans+=p; } cout << ans << endl; }