题意:给定 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. Tornado websocket应用

    应用场景 WebSocket 的特点如下 适合服务器主动推送的场景(好友上线,即时聊天信息,火灾警告,股票涨停等) 相对于Ajax和Long poll等轮询技术,它更高效,不耗费网络带宽和计算资源 它 ...

  2. 《高级软件测试》JIRA使用手册(一)JIRA基本情况

    JIRA 官方网站为:https://www.atlassian.com/software/jira 中文代理网站为:https://www.jira.cn 现版本:v7.3.0 Atlassian公 ...

  3. 完美解决ubuntu Desktop 16.04 中文版firefox在非root用户不能正常启动的问题

    ubuntu安装好后,默认安装有firefox浏览器,不过,非root的账户登录,双击firefox图标,居然出现如下提示:Your Firefox profile cannot be loaded. ...

  4. python 编码规范整理

    PEP8 Python 编码规范 一 代码编排1 缩进.4个空格的缩进(编辑器都可以完成此功能),不要使用Tap,更不能混合使用Tap和空格.2 每行最大长度79,换行可以使用反斜杠,最好使用圆括号. ...

  5. 聊一聊C#的Equals()和GetHashCode()方法

    博客创建一年多,还是第一次写博文,有什么不对的地方还请多多指教. 关于这次写的内容可以说是老生长谈,百度一搜一大堆.大神可自行绕路. 最近在看Jeffrey Richter的CLR Via C#,在看 ...

  6. 使用Python3爬虫抓取网页来下载小说

    很多时候想看小说但是在网页上找不到资源,即使找到了资源也没有提供下载,小说当然是下载下来用手机看才爽快啦! 于是程序员的思维出来了,不能下载我就直接用爬虫把各个章节爬下来,存入一个txt文件中,这样, ...

  7. cannot import name 'ChineseAnalyzer'

    在python3.6下安装jieba3k的时候报错: from jieba.analyse import ChineseAnalyzer ImportError: cannot import name ...

  8. Leetcode:Two Sum

    原题:https://leetcode.com/problems/two-sum/ 尝试了两种方法: 方法一: var twoSum = function(nums, target) { for(va ...

  9. iot:下一步要做的工作

    1.DeviceMessage抽象(定义&支持扩展)2.createDeviceMessage.analyseDeviceMessage(支持扩展)3.日志打印4.错误处理5.断线重连6.交互 ...

  10. 实现GridControl行动态改变行字体和背景色

    需求:开发时遇到一个问题, 需要根据GridControl行数据不同,实现不同的效果 在gridView的RowCellStyle的事件中实现,需要的效果 private void gridView1 ...