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. ASIHTTPRequest中文入门教程全集 http://www.zpluz.com/thread-3284-1-1.html

    本文转载至 目录  3 第  1  章  创建和运行请求  5 1.1.  创建一个同步请求  5 1.2.  创建一个异步请求  5 1.3.  使用程序块(blocks )  6 1.4.  使用 ...

  2. 使用Zxing.net实现asp.net mvc二维码功能

    新建一个html辅助类 public static class HtmlHelperExtensions { , , ) { var barcodeWriter = new BarcodeWriter ...

  3. Cow Contest(传递闭包)

    Cow Contest Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 10450   Accepted: 5841 Desc ...

  4. RMQ with Shifts(线段树)

    RMQ with Shifts Time Limit:1000MS     Memory Limit:65535KB     64bit IO Format:%I64d & %I64u Pra ...

  5. 九度OJ 1183:守形数 (数字特性)

    时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:3815 解决:2005 题目描述: 守形数是这样一种整数,它的平方的低位部分等于它本身. 比如25的平方是625,低位部分是25,因此25是 ...

  6. python cookbook第三版学习笔记十七:委托属性

    我们想在访问实例的属性时能够将其委托到一个内部持有的对象上,这经常用到代理机制上 class A:     def spam(self,x):         print("class_A: ...

  7. 关于随机浏览头伪装fake-UserAgent

    使用: from fake_useragent import UserAgent ua = UserAgent() #ie浏览器的user agent print(ua.ie) Mozilla/5.0 ...

  8. Python list,tuple,dict and set

    list 有序可变的集合 查找和插入的时间随着元素的增加而增加 占用空间小,浪费内存很少 tuple 有序只读不可变.因为tuple不可变,所以代码更安全.如果可能,能用tuple代替list就尽量用 ...

  9. [原创]java WEB学习笔记43:jstl 介绍,core库详解:表达式操作,流程控制,迭代操作,url操作

    本博客为原创:综合 尚硅谷(http://www.atguigu.com)的系统教程(深表感谢)和 网络上的现有资源(博客,文档,图书等),资源的出处我会标明 本博客的目的:①总结自己的学习过程,相当 ...

  10. mysql表数据压缩

    记得一次面试中,面试官问我是否知道表的压缩,这个时候我才知道mysql有个表压缩这么个功能,今天试用下看看表的压缩率怎么样. 这里分两个部分说明,第一部分:官方文档说明:第二部分:具体实例测试. [第 ...