Skip to content

Instantly share code, notes, and snippets.

@diego9627
Created October 24, 2012 06:28
Show Gist options
  • Save diego9627/3944381 to your computer and use it in GitHub Desktop.
Save diego9627/3944381 to your computer and use it in GitHub Desktop.
Engranes
#include<cstdio>
int colores[1000000];
bool iguales[1000000];
long long mcd(long long N,long long M){
if(N==0) return M;
else return mcd(M%N,N);
}
int main(){
long long N,M,k,T,i,d,in;
int c;
scanf("%lld %lld %lld",&N,&M,&k);
d=mcd(N,M);
for(i=0;i<d;i++){
scanf("%d",&colores[i]);
iguales[i]=true;
}
for(i=d;i<N;i++){
scanf("%d",&c);
if(c!=colores[i%d]) iguales[i%d]=false;
}
scanf("%lld",&T);
for(i=0;i<T;i++){
scanf("%lld",&in);
if(iguales[in%d]) printf("1");
else printf("0");
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment