結果

問題 No.186 中華風 (Easy)
ユーザー LayCurse
提出日時 2015-03-24 15:19:11
言語 C++11
(gcc 4.8.5)
結果
AC  
実行時間 25 ms
コード長 2,797 Byte
コンパイル時間 1,115 ms
使用メモリ 1,452 KB
最終ジャッジ日時 2019-10-09 09:17:36

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
0.in AC 15 ms
1,452 KB
1.in AC 6 ms
1,448 KB
2.in AC 8 ms
1,452 KB
3.in AC 3 ms
1,448 KB
4.in AC 13 ms
1,448 KB
5.in AC 12 ms
1,452 KB
6.in AC 17 ms
1,448 KB
7.in AC 15 ms
1,452 KB
8.in AC 21 ms
1,448 KB
9.in AC 20 ms
1,448 KB
A.in AC 25 ms
1,452 KB
B.in AC 9 ms
1,448 KB
C.in AC 10 ms
1,448 KB
D.in AC 11 ms
1,452 KB
E.in AC 4 ms
1,448 KB
F.in AC 3 ms
1,452 KB
G.in AC 3 ms
1,448 KB
system_test1.txt AC 6 ms
1,452 KB
system_test2.txt AC 15 ms
1,448 KB
system_test3.txt AC 16 ms
1,448 KB
system_test4.txt AC 15 ms
1,448 KB
system_test5.txt AC 16 ms
1,448 KB
テストケース一括ダウンロード

ソースコード

diff #
#include<bits/stdc++.h>
using namespace std;

#define REP(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)

#define mygc(c) (c)=getchar_unlocked()
#define mypc(c) putchar_unlocked(c)

#define ll long long
#define ull unsigned ll

void reader(int *x){int k,m=0;*x=0;for(;;){mygc(k);if(k=='-'){m=1;break;}if('0'<=k&&k<='9'){*x=k-'0';break;}}for(;;){mygc(k);if(k<'0'||k>'9')break;*x=(*x)*10+k-'0';}if(m)(*x)=-(*x);}
void reader(ll *x){int k,m=0;*x=0;for(;;){mygc(k);if(k=='-'){m=1;break;}if('0'<=k&&k<='9'){*x=k-'0';break;}}for(;;){mygc(k);if(k<'0'||k>'9')break;*x=(*x)*10+k-'0';}if(m)(*x)=-(*x);}
void reader(double *x){scanf("%lf",x);}
int reader(char c[]){int i,s=0;for(;;){mygc(i);if(i!=' '&&i!='\n'&&i!='\r'&&i!='\t'&&i!=EOF) break;}c[s++]=i;for(;;){mygc(i);if(i==' '||i=='\n'||i=='\r'||i=='\t'||i==EOF) break;c[s++]=i;}c[s]='\0';return s;}
template <class T, class S> void reader(T *x, S *y){reader(x);reader(y);}
template <class T, class S, class U> void reader(T *x, S *y, U *z){reader(x);reader(y);reader(z);}
template <class T, class S, class U, class V> void reader(T *x, S *y, U *z, V *w){reader(x);reader(y);reader(z);reader(w);}

void writer(int x, char c){int s=0,m=0;char f[10];if(x<0)m=1,x=-x;while(x)f[s++]=x%10,x/=10;if(!s)f[s++]=0;if(m)mypc('-');while(s--)mypc(f[s]+'0');mypc(c);}
void writer(ll x, char c){int s=0,m=0;char f[20];if(x<0)m=1,x=-x;while(x)f[s++]=x%10,x/=10;if(!s)f[s++]=0;if(m)mypc('-');while(s--)mypc(f[s]+'0');mypc(c);}
void writer(double x, char c){printf("%.15f",x);mypc(c);}
void writer(const char c[]){int i;for(i=0;c[i]!='\0';i++)mypc(c[i]);}
void writer(const char x[], char c){int i;for(i=0;x[i]!='\0';i++)mypc(x[i]);mypc(c);}
template<class T> void writerLn(T x){writer(x,'\n');}
template<class T, class S> void writerLn(T x, S y){writer(x,' ');writer(y,'\n');}
template<class T, class S, class U> void writerLn(T x, S y, U z){writer(x,' ');writer(y,' ');writer(z,'\n');}
template<class T> void writerArr(T x[], int n){int i;if(!n){mypc('\n');return;}rep(i,n-1)writer(x[i],' ');writer(x[n-1],'\n');}

char memarr[17000000]; void *mem = memarr;
#define MD 1000000007

template<class T> T GCD(T a,T b){T r; while(a){r=b; b=a; a=r%a;} return b;}
template<class T> T LCM(T a,T b){return a/GCD(a,b)*b;}

int N = 3;
ll X[3], Y[3];

int main(){
  int i, j, k;
  int cnt;
  ll res, add;

  rep(i,N){
    reader(X+i,Y+i);
    assert(0 <= X[i] && X[i] < Y[i] && Y[i] <= 1000000);
  }

  res = X[0];
  add = Y[0];
  cnt = 0;
  while(res%Y[1] != X[1]){
    res += add;
    cnt++;
    if(cnt > 1100000){ writerLn(-1); return 0; }
  }
  add = LCM(add,Y[1]);
  cnt = 0;
  while(res%Y[2] != X[2]){
    res += add;
    cnt++;
    if(cnt > 1100000){ writerLn(-1); return 0; }
  }

  if(res==0){
    res = LCM(LCM(Y[0], Y[1]), Y[2]);
  }

  writerLn(res);

  return 0;
}
0