結果

問題 No.186 中華風 (Easy)
ユーザー LayCurse
提出日時 2015-03-24 15:19:11
言語 C++11
(gcc 4.8.5)
結果
AC  
実行時間 23 ms / 2,000 ms
コード長 2,797 Byte
コンパイル時間 1,018 ms
使用メモリ 8,944 KB
最終ジャッジ日時 2020-05-31 03:21:41

テストケース

テストケース表示
入力 結果 実行時間
使用メモリ
testcase_00 AC 14 ms
8,900 KB
testcase_01 AC 6 ms
6,896 KB
testcase_02 AC 6 ms
8,944 KB
testcase_03 AC 2 ms
6,900 KB
testcase_04 AC 11 ms
8,944 KB
testcase_05 AC 11 ms
6,900 KB
testcase_06 AC 16 ms
8,896 KB
testcase_07 AC 13 ms
6,896 KB
testcase_08 AC 19 ms
8,944 KB
testcase_09 AC 18 ms
8,940 KB
testcase_10 AC 23 ms
8,944 KB
testcase_11 AC 7 ms
8,940 KB
testcase_12 AC 9 ms
8,940 KB
testcase_13 AC 10 ms
8,940 KB
testcase_14 AC 3 ms
6,900 KB
testcase_15 AC 2 ms
8,896 KB
testcase_16 AC 2 ms
8,944 KB
testcase_17 AC 5 ms
8,944 KB
testcase_18 AC 13 ms
8,940 KB
testcase_19 AC 13 ms
8,900 KB
testcase_20 AC 14 ms
6,896 KB
testcase_21 AC 14 ms
8,940 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