X问题

Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)

Total Submission(s): 3295    Accepted Submission(s): 1068

Problem Description

Input

Output

Sample Input

```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
```

Sample Output

```1
0
3
```

```#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
#define LL __int64
LL t , n , m , d , x , y , i , bb , aa , flag ;
void gcd(LL a,LL b)
{
if(b == 0)
{
d = a ; x = 1 ; y = 0 ;
}
else
{
gcd(b,a%b);
swap(x,y);
x = -x ; y = -y ;
y += (a/b)*x ;
}
return ;
}
LL a[30] , b[30] ;

int main()
{
scanf("%I64d", &t);
while(t--)
{
scanf("%I64d %I64d", &n, &m);
for(i = 0 ; i < m ; i++)
scanf("%I64d", &a[i]);
for(i = 0 ; i < m ; i++)
scanf("%I64d", &b[i]);
aa = a[0] ;
bb = b[0] ;
flag = 1 ;
for(i = 1 ; i < m ; i++)
{
gcd(aa,a[i]);
if( (b[i]-bb)%d != 0 )
flag = 0 ;
if( flag )
{
x = (b[i]-bb)/d*x ;
y = a[i] / d ;
x = ( x%y + y )%y ;
bb = bb + x * aa ;
aa = aa*a[i]/d ;
}
}
gcd(1,aa);
if( bb%d != 0 )
flag = 0 ;
if( flag )
{
x = ( bb/d )*x ;
y = aa / d ;
x = (x % y + y) % y ;
}
if( flag == 0 || x > n )
printf("0\n");
else
{
if( !x )
printf("%I64d\n", (n-x)/y );
else
printf("%I64d\n", (n-x)/y+1 );
}
}
return 0;
}
```

hdu1573X问题（不互素的中国剩余定理）,布布扣,bubuko.com

数论F - Strange Way to Express Integers（不互素的的中国剩余定理）

F - Strange Way to Express Integers Time Limit:1000MS     Memory Limit:131072KB     64bit IO Format:%I64d & %I64u Submit Status Description Elina is reading a book written by Rujia Liu, which introduces a strange way to express non-negative integers.

POJ 2891 中国剩余定理(不互素）

Strange Way to Express Integers Time Limit: 1000MS   Memory Limit: 131072K Total Submissions: 17877   Accepted: 6021 Description Elina is reading a book written by Rujia Liu, which introduces a strange way to express non-negative integers. The way is

hdu1573-X问题-（扩展欧几里得定理+中国剩余定理）

X问题 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 8416    Accepted Submission(s): 3066 Problem Description 求在小于等于N的正整数中有多少个X满足:X mod a[0] = b[0], X mod a[1] = b[1], X mod a[2] = b[2], -, X mod

lightoj 1319 - Monkey Tradition （中国剩余定理）

1319 - Monkey Tradition PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 32 MB In 'MonkeyLand', there is a traditional game called "Bamboo Climbing". The rules of the game are as follows: 1)       There are N monkeys who play

Chinese remainder theorem again（中国剩余定理）

C - Chinese remainder theorem again Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Description 我知道部分同学最近在看中国剩余定理,就这个定理本身,还是比较简单的: 假设m1,m2,…,mk两两互素,则下面同余方程组: x≡a1(mod m1) x≡a2(mod m2) … x≡ak(mod mk) 在0<=<m1m2…mk内有唯一解