結果

問題 No.186 中華風 (Easy)
ユーザー Lepton_s
提出日時 2015-04-20 00:14:44
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,609 bytes
コンパイル時間 815 ms
コンパイル使用メモリ 87,564 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-07-19 18:22:54
合計ジャッジ時間 1,654 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#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 __int128 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 gcd(ll a, ll b){
ll x, y;
return extgcd(a, b, x, y);
}
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++){
int bb, mm;
cin>>bb>>mm;
b[i] = bb;
m[i] = mm;
}
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<<(long long)((res==-1)?-1:(X-1+M)%M+1)<<endl;
return 0;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0