题意:给定 C,k1, b1, k2 找出所有的(a, b)满足 ak1⋅n+b1+ bk2⋅n−k2+1 = 0 (mod C)(n = 1, 2, 3, ...)  (1<=a, b <C)

1.  当n = 1时, a^(k1+b1) + b = 0 ( mod C)   => a^(2 * k1+b1) + b*a^(k1) = 0 ( mod C)     ①

当n = 2时, a^(2 * k1 + b1) + b^(k2 + 1) = 0 (mod C)       ②

所以  ① ,②结合  可以推出 b^(k2) = a^(k1)

所以求出 a ,b再判断是否符合本式即可

#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <time.h>
using namespace std;
typedef long long ll; ll pow_mod(int a,int n,int mod)
{
if(n == 0)
return 1;
ll x = pow_mod(a,n/2,mod);
ll ans = (ll)x*x%mod;
if(n %2 == 1)
ans = ans *a % mod;
return ans;
} int main()
{
int b1,k1,k2,mod;
int cas = 1;
while(scanf("%d%d%d%d",&mod,&k1,&b1,&k2) != EOF)
{
bool flag = false;
printf("Case #%d:\n",cas++);
for(int i = 1; i < mod; i++)
{
ll tmp = pow_mod(i,k1+b1,mod);
int b = mod - tmp;
ll tta = pow_mod(i,k1,mod);
ll ttb = pow_mod(b,k2,mod);
if(tta == ttb)
{
flag = true;
printf("%d %d\n",i,b);
}
}
if(!flag)
printf("-1\n");
}
return 0;
} 2. 求出1 - c所有的a ,b 的情况,再枚举n进行判断,但感觉不是很靠谱- - #include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <time.h>
using namespace std;
typedef long long ll; ll pow_mod(ll a,ll n,ll mod)
{
if(n == 0)
return 1;
ll x = pow_mod(a,n/2,mod);
ll ans = (ll)x*x%mod;
if(n %2 == 1)
ans = ans *a % mod;
return ans;
} int main()
{
ll b1,k1,k2;
ll mod;
int cas = 1;
while(scanf("%I64d%I64d%I64d%I64d",&mod,&k1,&b1,&k2) != EOF)
{
bool flag = true;
int ok;
printf("Case #%d:\n",cas++);
for(ll i = 1; i < mod; i++)
{
ll temp = pow_mod(i,k1+b1,mod);
ll b = (temp/mod + 1)*mod - temp;
ok = 1;
for(ll j = 2; j <= 100; j++)
{
ll ans1 = pow_mod(i, k1 * j + b1, mod);
ll ans2 = pow_mod(b, k2 * j - k2 + 1, mod);
ll ans = (ans1+ans2)%mod;
if(ans)
{
ok = 0;
break;
}
}
if(ok)
{
flag = 0;
printf("%I64d %I64d\n",i,b);
}
}
if(flag)
printf("-1\n");
}
return 0;
}

  

hdu 5478 (数论)的更多相关文章

  1. 2015上海网络赛 HDU 5478 Can you find it 数学

    HDU 5478 Can you find it 题意略. 思路:先求出n = 1 时候满足条件的(a,b), 最多只有20W对,然后对每一对进行循环节判断即可 #include <iostre ...

  2. GCD and LCM HDU 4497 数论

    GCD and LCM HDU 4497 数论 题意 给你三个数x,y,z的最大公约数G和最小公倍数L,问你三个数字一共有几种可能.注意123和321算两种情况. 解题思路 L代表LCM,G代表GCD ...

  3. HDU 5478 Can you find it 随机化 数学

    Can you find it Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pi ...

  4. HDU 4497 数论+组合数学

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4497 解题思路:将满足条件的一组x,z,y都除以G,得到x‘,y',z',满足条件gcd(x',y' ...

  5. hdu 4542 数论 + 约数个数相关 腾讯编程马拉松复赛

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=4542 小明系列故事--未知剩余系 Time Limit: 500/200 MS (Java/Others) ...

  6. hdu 4961 数论?

    http://acm.hdu.edu.cn/showproblem.php?pid=4961 给定ai数组; 构造bi, k=max(j | 0<j<i,a j%ai=0), bi=ak; ...

  7. hdu 1664(数论+同余搜索+记录路径)

    Different Digits Time Limit: 10000/4000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others ...

  8. hdu 3641 数论 二分求符合条件的最小值数学杂题

    http://acm.hdu.edu.cn/showproblem.php?pid=3641 学到: 1.二分求符合条件的最小值 /*================================= ...

  9. hdu 4059 数论+高次方求和+容斥原理

    http://acm.hdu.edu.cn/showproblem.php? pid=4059 现场赛中通过率挺高的一道题 可是容斥原理不怎么会.. 參考了http://blog.csdn.net/a ...

随机推荐

  1. iOS中CocoaPods的安装及错误详解

    什么是CocoaPods CocoaPods是OS X和iOS下的一个第三类库管理工具,通过CocoaPods工具我们可以为项目添加被称为"Pods"的依赖库(这些类库必须是Coc ...

  2. 【iOS】swift init构造器

    这几天在使用 Swift 重写原来的一个运动社交应用 SportJoin. 为什么要重写呢? 首先因为实在找不到设计师给我作图; 其次, 我也闲不下来, 想找一些项目做, 所以只好将原来的代码重写了. ...

  3. python之路--day13-模块

    1,什么是模块 模块就是系统功能的集合体,在python中,一个py文件就是一个模块, 例如:module.py 其中module叫做模块名 2,使用模块 2.1 import导入模块 首次带入模块发 ...

  4. 基于 Java NIO 实现简单的 HTTP 服务器

    1.简介 本文是上一篇文章实践篇,在上一篇文章中,我分析了选择器 Selector 的原理.本篇文章,我们来说说 Selector 的应用,如标题所示,这里我基于 Java NIO 实现了一个简单的 ...

  5. sts中maven

    建立一个maven web的工程 网上有很多关于maven的下载,配置等,我这里就不多说了. 下面介绍主要介绍关于在sts中建立一个maven时最开始出现的错误问题. 创建maven工程 file-& ...

  6. 新概念英语(1-3)Sorry, sir

    Does the man get his umbrella back? A:My coat and my umbrella please. B:Here is my ticket. A:Thank y ...

  7. 使用Spring Initializr创建项目

    Spring initializr 是Spring 官方提供的一个很好的工具,可以用来用来创建一个Spring boot 的项目.可以选择使用Maven管理或者使用Gradle管理,还可以选择使用的编 ...

  8. Linux中的重启命令

    1.系统重启: shutdowm    该命令安全地将系统关机. 有些用户会使用直接断掉电源的方式来关闭linux,这是十分危险的.因为linux与windows不同,其后台运行着许多进程,所以强制关 ...

  9. H5 仿ios select滚动选择器。框架。

    官网上描述的很详细,并且开源,轻量. 有兴趣的可以去尝试官网上的demo写的也很好,并且每个参数也解释的很详细. http://zhoushengfe.com/iosselect/website/in ...

  10. python判断素数的方法

    #运用python的数学函数 import math def isPrime(n): if n <= 1: return False for i in range(2, int(math.sqr ...