2013
12-12

# X问题

3
10 3
1 2 3
0 1 2
100 7
3 4 5 6 7 8 9
1 2 3 4 5 6 7
10000 10
1 2 3 4 5 6 7 8 9 10
0 1 2 3 4 5 6 7 8 9

1
0
3

by—cxlove

N===a1(mod r1)

N===a2(mod r2)

#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
#include<vector>
#include<cmath>
#define LL  long long
#define MOD 1000000007
#define eps 1e-6
#define N 100010
#define zero(a)  fabs(a)<eps
using namespace std;
LL extend_gcd(LL a,LL b,LL &x,LL &y){
if(b==0){
x=1;
y=0;
return a;
}
LL gcd=extend_gcd(b,a%b,x,y);
LL tmp=x;
x=y;
y=tmp-a/b*x;
return gcd;
}
int a[10],b[10];
int n,m;
int main(){
int t;
scanf("%d",&t);
while(t--){
scanf("%d%d",&n,&m);
for(int i=0;i<m;i++)
scanf("%d",&a[i]);
for(int j=0;j<m;j++)
scanf("%d",&b[j]);
LL a1,a2,b1,b2,x,y;
bool flag=false;
a1=a[0];b1=b[0];
for(int i=1;i<m;i++){
a2=a[i];b2=b[i];
LL gcd=extend_gcd(a1,a2,x,y);
if((b2-b1)%gcd){
flag=true;
break;
}
LL t=a2/gcd;
x=(x*(b2-b1))/gcd;
x=(x%t+t)%t;
b1=a1*x+b1;
a1=(a1*a2)/gcd;
b1=(b1%a1+a1)%a1;
}
if(flag||n<b1)
printf("0\n");
else
printf("%d\n",(n-b1)/a1+1-(b1==0?1:0));
}
return 0;
}

1. /*
* =====================================================================================
*
* Filename: 1366.cc
*
* Description:
*
* Version: 1.0
* Created: 2014年01月06日 14时52分14秒
* Revision: none
* Compiler: gcc
*
* Author: Wenxian Ni (Hello World~), [email protected]
* Organization: AMS/ICT
*
* =====================================================================================
*/

#include
#include

using namespace std;

int main()
{
stack st;
int n,i,j;
int test;
int a[100001];
int b[100001];
while(cin>>n)
{
for(i=1;i>a[i];
for(i=1;i>b[i];
//st.clear();
while(!st.empty())
st.pop();
i = 1;
j = 1;

while(in)
break;
}
while(!st.empty()&&st.top()==b[j])
{
st.pop();
j++;
}
}
if(st.empty())
cout<<"YES"<<endl;
else
cout<<"NO"<<endl;
}
return 0;
}