码迷,mamicode.com
首页 > 其他好文 > 详细

中国剩余定理【数论】

时间:2019-01-23 01:29:30      阅读:175      评论:0      收藏:0      [点我收藏+]

标签:inf   https   .com   art   html   ant   pac   thml   margin   

 

今有物不知其数,三三数之剩二,五五数之剩三,七七数之剩二。问物几何?

https://www.cnblogs.com/freinds/p/6388992.html
https://blog.csdn.net/niiick/article/details/80229217
 
技术分享图片
 
技术分享图片

 

void exgcd(int a,int b,int &x,int &y)
{
    if(b==0){ x=1; y=0; return;}
    exgcd(b,a%b,x,y);
    int tp=x;
    x=y; y=tp-a/b*y;
}

int china()
{
    int ans=0,lcm=1,x,y;
    for(int i=1;i<=k;++i) lcm*=b[i];
    for(int i=1;i<=k;++i)
    {
        int tp=lcm/b[i];
        exgcd(tp,b[i],x,y);
        x=(x%b[i]+b[i])%b[i];//x要为最小非负整数解
        ans=(ans+tp*x*a[i])%lcm;
    }
    return (ans+lcm)%lcm;
}

 


中国剩余定理【数论】

标签:inf   https   .com   art   html   ant   pac   thml   margin   

原文地址:https://www.cnblogs.com/donke/p/10306778.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!