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 a^(k1⋅n+b1 )+ b^(k2⋅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

题目意思一开始理解错了,然后以为只要能找到一个n满足条件,这组(a, b)就算满足条件。

原来是要所有n满足才行,这样题目就是任意型问题,相对会好解决一点。

既然是任意,肯定考虑先取些特殊值试试。

自然考虑取n=1,

发现a^(k1+b1)
+ b = 0(mod c)

这样就把b在模c情况下的值求出来了。

b = - a^(k1+b1)(mod
c)

然后继续带入n = 2,

a^(2k1+b1)
+ b^(k2+1) = 0(mod c)

大胆猜测这个式子成立,n取任何数都会成立。

因为n加1时,a的指数和b的指数增量是一定的,那么n取任何数时,必然和n-1之前相差的式子是一个定值多项式。

首先n
= 2时,

可以得到b^(k2+1)
= -a^(2k1+b1) = -a^(k1+b1)*a^k1 = b*a^k1

这一步可以通过n = 1得到的结论两边消掉一个b,得:

b^k2 =
a^k1。

也就是说由n = 1满足,让n = 2满足的条件是b^k2 = a^k1。

基本是可以YY一下,由n = 2满足,让n = 3满足的条件是b^k2 = a^k1。

即由n
= k满足,让n
= k+1满足的条件是b^k2
= a^k1。

这一步用数学归纳法随便搞一搞就可以验证了。

不知道是什么情况,比赛时是n = 1得出b, n = 2验证b过的。

现在重写了一遍死活T。。。

后来换成n
= 2时验证式子b^k2
= a^k1就能过了。。

代码:

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <string>
#define LL long long using namespace std; int c, k1, b1, k2; //快速幂m^n
LL quickPow(LL x, LL n)
{
LL a = ;
while (n)
{
a *= n& ? x : ;
a %= c;
n >>= ;
x *= x;
x %= c;
}
return a;
} bool judge(LL a, LL b)
{
if (quickPow(a, k1) != quickPow(b, k2))
return false;
else
return true;
} void work()
{
LL b;
bool flag = false;
for (int a = ; a < c; ++a)
{
b = -quickPow(a, (b1+k1)%(c-));
b = (b+c)%c;
if (judge(a, b))
{
printf("%d %I64d\n", a, b);
flag = true;
}
}
if (!flag)
printf("-1\n");
} int main()
{
//freopen("test.in", "r", stdin);
int times = ;
while (scanf("%d%d%d%d", &c, &k1, &b1, &k2) != EOF)
{
printf("Case #%d:\n", times);
work();
times++;
}
return ;
}

ACM学习历程—HDU5478 Can you find it(数论)(2015上海网赛11题)的更多相关文章

  1. ACM学习历程——HDU5017 Ellipsoid(模拟退火)(2014西安网赛K题)

    ---恢复内容开始--- Description Given a 3-dimension ellipsoid(椭球面) your task is to find the minimal distanc ...

  2. ACM学习历程—HDU5476 Explore Track of Point(平面几何)(2015上海网赛09题)

    Problem Description In Geometry, the problem of track is very interesting. Because in some cases, th ...

  3. ACM学习历程—HDU5475 An easy problem(线段树)(2015上海网赛08题)

    Problem Description One day, a useless calculator was being built by Kuros. Let's assume that number ...

  4. ACM学习历程—HDU 5025 Saving Tang Monk(广州赛区网赛)(bfs)

    Problem Description <Journey to the West>(also <Monkey>) is one of the Four Great Classi ...

  5. ACM学习历程—HDU 5459 Jesus Is Here(递推)(2015沈阳网赛1010题)

    Sample Input 9 5 6 7 8 113 1205 199312 199401 201314 Sample Output Case #1: 5 Case #2: 16 Case #3: 8 ...

  6. ACM学习历程—HDU 5451 Best Solver(Fibonacci数列 && 快速幂)(2015沈阳网赛1002题)

    Problem Description The so-called best problem solver can easily solve this problem, with his/her ch ...

  7. ACM学习历程—HDU 5443 The Water Problem(RMQ)(2015长春网赛1007题)

    Problem Description In Land waterless, water is a very limited resource. People always fight for the ...

  8. ACM学习历程—HDU 5446 Unknown Treasure(数论)(2015长春网赛1010题)

    Problem Description On the way to the next secret treasure hiding place, the mathematician discovere ...

  9. ACM学习历程—HDU5407 CRB and Candies(数论)

    Problem Description CRB has N different candies. He is going to eat K candies.He wonders how many co ...

随机推荐

  1. iOS tableView自定义删除按钮

    // 自定义左滑显示编辑按钮 - (NSArray<UITableViewRowAction*>*)tableView:(UITableView *)tableView editActio ...

  2. 2016/05/17 thinkphp3.2.2 分页的使用:①在Home下设置Publics文件夹或在thinkPHP下library的vender 把page.class.php 考贝进入 ②通过new 实例化方式调用 $page=new \Home\Publics\Page($total,3);

    注意分页的方法有两种:一种是thinkphp3.2 自带的   另一种是之前新闻页用过的     显示效果稍有差别 显示效果: 细节问题: ①搜索页面  要加session判断   和  分页 ②修改 ...

  3. poj2891(线性同余方程组)

    一个exgcd解决一个线性同余问题,多个exgcd解决线性同余方程组. Strange Way to Express Integers Time Limit: 1000MS   Memory Limi ...

  4. KPI、KPA、OKR三者的区别

    KPI.KPA或者OKR并不是水火不相容有你无我的概念,针对不对的业务状态.管理模式应该有所选择.以下是介绍它们之间的区别. 什么是KPI关键绩效指标 KPI(key performance indi ...

  5. Nginx结合GeoIP库

    1. 编译nginx时带上geoip模块 # wget http://nginx.org/download/nginx-x.x.x.tar.gz # tar zxvf nginx-x.x.x.tar. ...

  6. GCD多线程在swift中的变化

    1.异步线程加载主线程刷新 DispatchQueue.global().async { // TODO:执行异步线程网络请求 DispatchQueue.main.async(execute: { ...

  7. centos出现-bash: /usr/bin/php: 没有那个文件或目录解决方法

    造成这个的原因是因为找不到php的执行文件导致的,原先我是安装的php5.4,然后卸载了重新安装php7,导致php可执行文件没有放到$PATH中,可以在终端测试:php -v,如果报错bash: / ...

  8. mysql mariadb 乱码

    mysql 创建临时表 CREATE TEMPORARY TABLE tmp_table SELECT COUNT(*) AS num FROM student_info GROUP BY LEFT( ...

  9. 云计算服务的三种类型(SaaS、PaaS、IaaS)

    云计算可以帮助企业降低IT方面的成本和复杂性,并获得他们蓬勃发展所需的灵活性与敏捷性.但是,规划出通往云的明确路径并非易事.毕竟用户需要看透与云相关的市场大肆宣传,然后理解并分析不同种类的云计算模式的 ...

  10. 坑爹的shell 空格

    shell 空格很敏感,被线上代码坑了,占个位,回头好好整理一下