题意:给定 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. C语言--第一周作业(更改)

    *********************学习总结********************* 1.所用词典: 2.Git截图: *********************遇到的问题和解决方法***** ...

  2. JQuery 动态加载iframe.

    html: <iframe id="ifm" style="width:inherit;height:inherit" runat="serve ...

  3. linux查看文件内容的常见命令

    1.cat命令,显示文件的所有内容,内容过多则显示最后一屏一般用于内容较少文件 2.more命令,分页显示文件的内容一般用于文件内容过多的文件,回车显示下一行,空格显示下一页,q/Q退出 3.head ...

  4. Gitlab的安装及项目新建

    1. Gitlab的安装及仓库创建 1.1下载gitlab安装包 1).官网下载速度较慢 建议先行下载 国内的源里面可以找到最新的版本https://mirrors.tuna.tsinghua.edu ...

  5. Mego开发文档 - 复杂保存操作

    复杂保存操作 Mego框架还提供了更强大的数据更新API,以简化开发工作,同时也保证的性能. 指定属性添加数据 本列中指定插入一个数据对象,并且只会插入三列数据,最后两个属性是以表达式的形式插入. u ...

  6. Python入门之函数的装饰器

    本章目录: 装饰器: 一.为什么要用装饰器 二.什么是装饰器 三.无参装饰器 四.装饰器语法糖 五.认证装饰器实现 六.叠加多个装饰器 七.带参装饰器 ======================== ...

  7. 哪些异常是RuntimeException?Sql异常属于RuntimeException吗?Spring下SQL异常事务回滚

    一,为什么框架中根本没有对Exception的一般子类进行回滚配置,异常发生时,事务都进行了回滚 ,说好的只会对RuntimeException(Unchecked 非受检异常)回滚呢? 此时,我们就 ...

  8. python 杂货铺

    python 杂货铺之不知道的python操作 1.交互模式下的神奇的_ windos中cmd交互模式中下(python2,python3),最近一个表达式的值赋给变量 _.这样我们就可以把它当作一个 ...

  9. Qt编译oci教程

    Qt编译OCI教程 上图oci.dll 不是oci.lib 我很奇怪网上大部分教程都是写的oci.lib,其实大家可以去oracle目录找一下这个文件,看看是不是在这个目录,我找了一下没发现.而lib ...

  10. Java-NIO(五):通道(Channel)的数据传输与内存映射文件

    通道(Channel)的数据传输(采用非直接缓冲区) @Test public void testChannel() throws IOException { FileInputStream file ...