hdu 5478 (数论)
题意:给定 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 (数论)的更多相关文章
- 2015上海网络赛 HDU 5478 Can you find it 数学
HDU 5478 Can you find it 题意略. 思路:先求出n = 1 时候满足条件的(a,b), 最多只有20W对,然后对每一对进行循环节判断即可 #include <iostre ...
- GCD and LCM HDU 4497 数论
GCD and LCM HDU 4497 数论 题意 给你三个数x,y,z的最大公约数G和最小公倍数L,问你三个数字一共有几种可能.注意123和321算两种情况. 解题思路 L代表LCM,G代表GCD ...
- 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 ...
- HDU 4497 数论+组合数学
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4497 解题思路:将满足条件的一组x,z,y都除以G,得到x‘,y',z',满足条件gcd(x',y' ...
- hdu 4542 数论 + 约数个数相关 腾讯编程马拉松复赛
题目:http://acm.hdu.edu.cn/showproblem.php?pid=4542 小明系列故事--未知剩余系 Time Limit: 500/200 MS (Java/Others) ...
- 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; ...
- hdu 1664(数论+同余搜索+记录路径)
Different Digits Time Limit: 10000/4000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others ...
- hdu 3641 数论 二分求符合条件的最小值数学杂题
http://acm.hdu.edu.cn/showproblem.php?pid=3641 学到: 1.二分求符合条件的最小值 /*================================= ...
- hdu 4059 数论+高次方求和+容斥原理
http://acm.hdu.edu.cn/showproblem.php? pid=4059 现场赛中通过率挺高的一道题 可是容斥原理不怎么会.. 參考了http://blog.csdn.net/a ...
随机推荐
- 创建带缩进的XML
from xml.etree import ElementTree as ET from xml.dom import minidom root = ET.Element('}) son=ET.Sub ...
- Hibernate之深入持久化对象
Hibernate是一个彻底的O/R Mapping 框架.之所以说彻底,是因为相对于其他的 框架 ,如Spring JDBC,iBatis 需要手动的管理SQL语句,Hibernate采用了完全 面 ...
- Linux下关闭Tomcat残留线程
ps -ef | grep tomcat kill -9 {pid}
- CentOS 7 安装Graphite
Graphite简介 Graphite是一个Python编写的企业级开源监控工具,采用django框架,用来收集服务器所有的即时状态,用户请求信息,Memcached命中率,RabbitMQ消息服务器 ...
- WebDriverException : Missing 'type' parameter
下载最新的geckodriver即可 v0.17.0 Releases · mozilla/geckodriver · GitHubhttps://github.com/mozilla/geckodr ...
- 【漏洞复现】PHPCMS wap模块 SQL注入(附EXP)
漏洞影响版本:v9.5.8.v9.6.0 Step1: 访问:http://www.xxx.com/index.php?m=wap&a=index&siteid=1, 获取返回的coo ...
- js回顾(DOM中标签的CRUD,表格等)
01-DOM中的创建和添加标签 02-删除替换克隆标签 03-全选全不选反选 04-新闻字体 05-表格增删 06-动态生成表格 07-表格隔行变色 08-左到右右到左(将左边的标签移动到右边) 09 ...
- 新概念英语(1-7)Are you a teacher?
What is Robert's job? A:I am a new student. My name is Robert. B:Nice to meet you. My name's Sophie. ...
- SpringCloud的服务消费者 (二):(rest+feign/ribbon)声明式访问注册的微服务
采用Ribbon或Feign方式访问注册到EurekaServer中的微服务.1.Ribbon实现了客户端负载均衡,Feign底层调用Ribbon2.注册在EurekaServer中的微服务api,不 ...
- ejs注释问题
项目中遇到一个问题: 代码如下: 但是代码如下时,却不会出现bug: bug的导火索是ejs的注释: 因为我没有用对注释,所以被注释部分的if语句仍旧生效了. bug的根本原因是没有对mod类型进行判 ...