結果
| 問題 |
No.186 中華風 (Easy)
|
| コンテスト | |
| ユーザー |
Lepton_s
|
| 提出日時 | 2015-04-20 00:09:09 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,492 bytes |
| コンパイル時間 | 757 ms |
| コンパイル使用メモリ | 84,304 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-07-04 19:03:44 |
| 合計ジャッジ時間 | 1,449 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 21 WA * 2 |
ソースコード
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <sstream>
#include <functional>
#include <map>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <list>
#include <numeric>
using namespace std;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const int INF = 1<<25;
typedef pair<int,int> P;
typedef long long ll;
typedef unsigned long long ull;
ll mod = 1e9+7;
ll pow_mod(ll a, ll n, ll m){
ll r = 1;
while(n){
if(n&1) r = r*a%m;
a = a*a%m;
n >>= 1;
}
return r;
}
ll extgcd(ll a, ll b, ll &x, ll &y){
ll d = a;
if(b){
d = extgcd(b, a%b, y, x);
y -= (a/b)*x;
} else {
x = 1; y = 0;
}
return d;
}
ll mod_inv(ll a, ll m){
ll x, y;
extgcd(a, m, x, y);
return (m+x%m)%m;
}
int main(){
ll n;
// cin>>n;
n = 3;
vector<ll> b(n), m(n);
for(int i = 0; i < n; i++) cin>>b[i]>>m[i];
ll res = -2;
/*
for(int i = 0; i < n; i++){
for(int j = i+1; j < n; j++){
ll gm = __gcd(m[i], m[j]);
if(b[i]%gm!=b[j]%gm) res = -1;
}
}
if(res==-1){
cout<<-1<<endl;
return 0;
}
*/
ll X = 0, M = 1;
for(int i = 0; i < n; i++){
ll A = M, B = b[i]-X, D = __gcd(m[i], M);
if(B%D){
res = -1;
break;
}
A /= D;
B /= D;
m[i] /= D;
ll T = B%m[i]*mod_inv(A, m[i])%(m[i]);
X = X+M*T;
M *= m[i];
X = (X%M+M)%M;
}
cout<<(res==-1?-1:(X+M)%M)<<endl;
return 0;
}
Lepton_s