結果
| 問題 |
No.186 中華風 (Easy)
|
| コンテスト | |
| ユーザー |
Lepton_s
|
| 提出日時 | 2015-04-20 00:00:46 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,423 bytes |
| コンパイル時間 | 614 ms |
| コンパイル使用メモリ | 84,520 KB |
| 実行使用メモリ | 6,948 KB |
| 最終ジャッジ日時 | 2024-07-04 19:02:14 |
| 合計ジャッジ時間 | 1,317 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 6 WA * 17 |
ソースコード
#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;
ll T = B/D*mod_inv(A/D, m[i]/D)%(m[i]/D);
X = X+M*T;
M *= m[i]/D;
}
cout<<(res<0?-1:X%M)<<endl;
return 0;
}
Lepton_s