下面这个程序可以对付非互素的同余
#include 
#include 
#include 
#include 
using namespace std;

__int64 x, y, t;

__int64 egcd(__int64 a, __int64 b) 
{
    if (b==0)   
    {
        x=1;      
        y=0;   
        return a;   
    }
    else 
    {
        __int64 e=egcd(b,a % b); 
        t=x; 
        x=y;
        y=t-a/b*y;   
        return e;   
    }
}

__int64 gcd(__int64 x, __int64 y)
{
    if (!x || !y)
        return x > y ? x : y;
    for (__int64 t; t = x % y; x = y, y = t);
    return y;
}
__int64 mm[10],rr[10];

int main() 
{
    //freopen("in.txt", "r", stdin); 
    __int64 m1,m2,r1,r2,d,c,t;
    bool flag;   
    __int64 n;   
    __int64 tc,cnt=0;
    scanf ("%I64d",&tc);

    while (tc--)    
    {
        cnt++;
        scanf ("%I64d",&n);
        flag=0;          
        for (__int64 i=0;i1)
            {
                r1=mm[0];
                __int64 ans=1;
                for (int i=1;i
posted on 2011-11-16 18:26  cchun  阅读(225)  评论(0编辑  收藏  举报