Can you find it

Time Limit: 8000/5000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 450    Accepted Submission(s): 208

Problem Description
Given a prime number C(1≤C≤2×105), and three integers k1, b1, k2 (1≤k1,k2,b1≤109). Please find all pairs (a, b) which satisfied the equation ak1⋅n+b1 + bk2⋅n−k2+1 = 0 (mod C)(n = 1, 2, 3, ...).
 
Input
There are multiple test cases (no more than 30). For each test, a single line contains four integers C, k1, b1, k2.
 
Output
First, please output "Case #k: ", k is the number of test case. See sample output for more detail.
Please output all pairs (a, b) in lexicographical order. (1≤a,b<C). If there is not a pair (a, b), please output -1.
 
Sample Input
23 1 1 2
 
Sample Output
Case #1:
1 22
 
Source
 
Recommend
hujie
 
 
首先想n为1,2,3……都要成立,所以先保证n=1成立,然后验证其他是否成立,把等式左边的b那一项移到右边,除一下,发现每次增量都是a^k1 和b^k2 所以只要n=2成立,后面的都成立。
下回这种题不要怕,还是可以做的。
 
#include<queue>
#include<math.h>
#include<stdio.h>
#include<string.h>
#include<string>
#include<iostream>
#include<algorithm>
using namespace std;
#define N 1234567
#define M 12
int c, k1, b1, k2;
bool flag;
int quickpow(int m,int n,int k)// m^n % k
{
int b = ;
while (n > )
{
if (n & )
b = (b*m)%k;
n = n >> ;
m = (m*m)%k;
}
return b;
}
int main()
{
int tt = ; int b;
while(~scanf("%d %d %d %d", &c, &k1, &b1, &k2))
{ printf("Case #%d:\n", tt++);
flag = ;
for(int a = ; a < c; a++)
{
b = c - quickpow(a,k1+b1,c);
if( ( quickpow(a, k1*+b1, c) + quickpow(b, k2*-k2+, c) ) %c == )
{
printf("%d %d\n",a,b);
flag = ;
}
}
if(flag == )
printf("-1\n");
}
return ;
}

HDU 5478 Can you find it的更多相关文章

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

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

  2. 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 ...

  3. HDU 5478 Can you find it(快速幂)

    Problem Description Given a prime number C(1≤C≤2×105), and three integers k1, b1, k2 (1≤k1,k2,b1≤109 ...

  4. HDU 5478 Can you find it(数学问题)

    题目大意: 给你  ak1⋅n+b1+ bk2⋅n−k2+1 = 0 (mod C)(n = 1, 2, 3, ...). 要求所有的n都满足上述的式子. 问这样的a,b 有多少对?   分析这个问题 ...

  5. hdu 5478 (数论)

    ⋅n+b1⋅n−k2+1 = 0 (mod C)(n = 1, 2, 3, ...)  (1<=a, b <C) 1.  当n = 1时, a^(k1+b1) + b = 0 ( mod ...

  6. HDOJ 2111. Saving HDU 贪心 结构体排序

    Saving HDU Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  7. 【HDU 3037】Saving Beans Lucas定理模板

    http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...

  8. hdu 4859 海岸线 Bestcoder Round 1

    http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...

  9. HDU 4569 Special equations(取模)

    Special equations Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u S ...

随机推荐

  1. loj2003 「SDOI2017」新生舞会

    分数规划+KM 算法 这个KM不好,看算法竞赛进阶指南的 #include <iostream> #include <cstring> #include <cstdio& ...

  2. Python内置函数5

    Python内置函数5 1.format参考前面字符串方法中的format 2.frozenset([iterable]) iterable -- 可迭代的对象,比如列表.字典.元组等等 返回一个冻结 ...

  3. SG博弈函数模板

    下面这两个模版应该就比较严密了,这个里边的f[]是从零开始的. 转载出处:转自:http://blog.csdn.net/primoblog/article/details/13376057 1.sg ...

  4. Mysql 主外键与索引之间的区别和联系

    系数据库依赖于主键,它是数据库物理模式的基石.主键在物理层面上只有两个用途: 惟一地标识一行. 作为一个可以被外键有效引用的对象. 索引是一种特殊的文件(InnoDB数据表上的索引是表空间的一个组成部 ...

  5. docker命令解析

    1.docker run --name lllllll  -d -p 8080:8080 -p 9000:9000  镜像id          将docker8080端口映射到服务器的8080端口 ...

  6. Java线程的学习_线程池

    系统启动一个新线程需要很高的成本,因为它涉及与操作系统交互.在这种情况下,使用线程池可以很好地提高性能,尤其是当程序中需要创建大量生存期很短暂的线程时. 线程池在系统启动时即创建大量空闲的线程,程序将 ...

  7. Nastya Studies Informatics

    Nastya Studies Informatics   time limit per test 1 second   memory limit per test 256 megabytes   in ...

  8. 【Codeforces Round #506 (Div. 3) 】

    A:https://www.cnblogs.com/myx12345/p/9844334.html B:https://www.cnblogs.com/myx12345/p/9844368.html ...

  9. Yii 之视图

    控制器方法代码: public function actionIndex(){ $data = array( 'name' => 'zhangsan', 'age' => 12, 'add ...

  10. hdu 1224 最长路

    开始用dijkstra直接求,发现不行,算法问题(1-2,(30),2-4(20),1--3(10),3--4(100)最后一个点无法更新,导致错误),后用取负,加大数法也没过. 现在(寒假了):求负 ...