結果

問題 No.186 中華風 (Easy)
ユーザー Lepton_sLepton_s
提出日時 2015-04-20 00:14:44
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,609 bytes
コンパイル時間 780 ms
コンパイル使用メモリ 78,924 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-27 00:43:26
合計ジャッジ時間 1,771 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 1 ms
4,384 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 1 ms
4,376 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 1 ms
4,376 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 2 ms
4,380 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 2 ms
4,376 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

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;
}
0