设为首页 加入收藏

TOP

poj1006
2014-11-23 20:00:46 来源: 作者: 【 】 浏览:13
Tags:poj1006

数论跪了三天。。

这个题不难得到(n+d)%23=p; (n+d)%28=e; (n+d)%33=i

如何求解?

首先介绍一个所谓“逆”的概念。

给定整数a,有(a,m)=1,称ax=1(mod m)的一个解叫做a模m的逆。

下面给出求逆的程序。

#include    
#include    
  
using namespace std;  
  
typedef long long LL;  
  
void gcd(LL a, LL b, LL &d, LL &x, LL &y)  
{  
    if(!b)  
    {  
        d = a, x = 1, y = 0;  
    }  
    else  
    {  
        gcd(b, a %b, d, y, x);  
        y -= x * (a/b);  
    }  
}  
LL inv(LL a, LL n)  
{  
    LL d, x, y;  
    gcd(a,n,d,x,y);  
    return d == 1   (x + n) % n : -1;  
}  
int main()  
{  
    LL a, m;  
    while(cin>> a>>m)  
    {  
        cout << inv(a, m) < 
 

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇二叉排序树 下一篇HDU 4568 SPFA + TSP

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·Python爬虫教程(从 (2025-12-26 16:49:14)
·【全269集】B站最详 (2025-12-26 16:49:11)
·Python爬虫详解:原 (2025-12-26 16:49:09)
·Spring Boot Java: (2025-12-26 16:20:19)
·Spring BootでHello (2025-12-26 16:20:15)