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
 

 
没做出的主要原因在于没有想到化简式子的方法,快速幂还是很容易就想到的,但是以前并没有用过这种方法,主要是题意没有理解好,把n看的太重要,其实题意就是告诉你n=1,2...的时候肯定成立,并不是选其中一个n成立!!!!那么就可以只取1,2来进行计算。
 
n=1时,ak1+b1+ b = 0 (mod C)------------------①
n=2时,a2*k1+b1+ bk2+1 = 0 (mod C)----------②
 
①*ak1 ,等式仍成立,a2*k1+b1+ak1 *b = 0 (mod C)-------------③
 
由方程②=③,可推出 :ak1 (mod C) = bk2 (mod C)---------------*
 
遍历a:1~c-1,利用快速幂从①计算出b,再利用快速幂计算*式等号两边,比较是否相等。
 
 #include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<queue>
#include<stack>
#include<math.h>
#include<vector>
#include<map>
#include<set>
#include<stdlib.h>
#include<cmath>
#include<string>
#include<algorithm>
#include<iostream>
#define exp 1e-10 using namespace std; __int64 Quick_Mod(int a, int b, int m)
{
__int64 res = ,term = a % m;
while(b)
{
if(b & ) res = (res * term) % m;
term = (term * term) % m;
b >>= ;
}
return res%m;
} int main()
{
int c,k1,b1,k2,t;
int f;
t=;
while(cin>>c>>k1>>b1>>k2)
{
cout<<"Case #"<<t++<<":"<<endl;
f=;
int a,b,x,y;
for(a=;a<c;++a)
{
x=Quick_Mod(a,k1,c);
b=c-Quick_Mod(a,k1+b1,c);
y=Quick_Mod(b,k2,c);
if(x==y)
{
f=;
cout<<a<<" "<<b<<endl;
}
}
if(f==)
{
cout<<-<<endl;
} } return ;
}
 

HDU 5478 Can you find it(快速幂)的更多相关文章

  1. hdu 5667 BestCoder Round #80 矩阵快速幂

    Sequence  Accepts: 59  Submissions: 650  Time Limit: 2000/1000 MS (Java/Others)  Memory Limit: 65536 ...

  2. hdu 4686 Arc of Dream(矩阵快速幂)

    链接:http://acm.hdu.edu.cn/showproblem.php?pid=4686 题意: 其中a0 = A0ai = ai-1*AX+AYb0 = B0bi = bi-1*BX+BY ...

  3. HDU 4686 Arc of Dream 矩阵快速幂,线性同余 难度:1

    http://acm.hdu.edu.cn/showproblem.php?pid=4686 当看到n为小于64位整数的数字时,就应该有个感觉,acm范畴内这应该是道矩阵快速幂 Ai,Bi的递推式题目 ...

  4. HDU 2157 How many ways?? (邻接矩阵快速幂)

    http://acm.hdu.edu.cn/showproblem.php?pid=2157 题意 : 给定一个有向图,问从A点恰好走k步(允许重复经过边)到达B点的方案数mod p的值   从这道题 ...

  5. HDU - 4990 Reading comprehension 【矩阵快速幂】

    题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=4990 题意 初始的ans = 0 给出 n, m for i in 1 -> n 如果 i 为奇 ...

  6. HDU 1005 Number Sequence:矩阵快速幂

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1005 题意: 数列{f(n)}: f(1) = 1, f(2) = 1, f(n) = ( A*f(n ...

  7. HDU 2604 Queuing( 递推关系 + 矩阵快速幂 )

    链接:传送门 题意:一个队列是由字母 f 和 m 组成的,队列长度为 L,那么这个队列的排列数为 2^L 现在定义一个E-queue,即队列排列中是不含有 fmf or fff ,然后问长度为L的E- ...

  8. HDU 5793 A Boring Question (逆元+快速幂+费马小定理) ---2016杭电多校联合第六场

    A Boring Question Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others ...

  9. hdu 1575 Tr A(矩阵快速幂)

    今天做的第二道矩阵快速幂题,因为是初次接触,各种奇葩错误整整调试了一下午.废话不说,入正题.该题应该属于矩阵快速幂的裸题了吧,知道快速幂原理(二进制迭代法,非递归版)后,剩下的只是处理矩阵乘法的功夫了 ...

随机推荐

  1. 转换到 COFF 期间失败: 文件无效或损坏 解决方法

    转自csdn 终极解决方案:VS2010在经历一些更新后,建立Win32 Console Project时会出“error LNK1123” 错误,解决方案为将 项目|项目属性|配置属性|清单工具|输 ...

  2. C++ Code_StatusBar

    主题 1. 创建状态栏 并显示 2. 在状态栏中显示进度条 3. MDI文档显示和隐藏状态栏 4. 5.     代码::创建状态栏 并显示 //手动添加3个ICON //////////////// ...

  3. 使用TypeDescriptor给类动态添加Attribute

    给类动态添加Attribute一直是我想要解决的问题,从msdn里找了很久,到Stack Overflow看了不少文章,算是最终有了答案. 先是有这样的一段解释 Attributes are stat ...

  4. 日志记录到txt文件

    using System;using System.Collections.Generic;using System.IO;using System.Linq;using System.Web;usi ...

  5. 【JavaScript】Javascript中的函数声明和函数表达式

    Javascript有很多有趣的用法,在Google Code Search里能找到不少,举一个例子: <script> ~function() { alert("hello, ...

  6. change netbeans look and feel

    change netbeans look and feel: 方法一: 下载地址:https://kenai.com/projects/nbsubstance/downloads/directory/ ...

  7. [MongoDB] Query, update, index and group

    /* 1. Query Operators */ db.posts.find({ viewsCount: {$get: 1000, $lte: 3000} }, {_id: 0, viewsCount ...

  8. SQLServer恢复表级数据

    最近几天,公司的技术维护人员频繁让我恢复数据库,因为他们总是少了where条件,导致update.delete出现了无法恢复的后果,加上那些库都是几十G.恢复起来少说也要十几分钟.为此,找了一些资料和 ...

  9. cocos2dx-jsb 跨语言调用及第三方集成 - 过程记录

    1:C++中调用js方法: 问题:ios中当用户通过home键将游戏转入后台时,调用js中的暂停游戏方法: AppDelegate::applicationDidEnterBackground() 和 ...

  10. knockout 监控数组的缺点

    knockout的监控数组没有想象中的强大,只能监控数组元素的位置变化,或个数的增减,然后对视图对应区域进行同步. <!DOCTYPE html> <html> <hea ...