Can you find it

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

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
 
思路:枚举a。当n=1时,ak1+b+b=0(mod C),则b=C-ak1+b(mod C)。再利用n=2,验证b是否正确。
#include <cstdio>
using namespace std;
typedef long long LL;
LL C,k1,b1,k2;
LL npow(LL x,LL n,LL mod)
{
LL res=;
while(n>)
{
if(n&) res=(res*x)%mod;
x=(x*x)%mod;
n>>=;
}
return res;
}
int main()
{
int cas=;
while(scanf("%lld%lld%lld%lld",&C,&k1,&b1,&k2)!=EOF)
{
bool tag=false;
printf("Case #%d:\n",++cas);
for(LL a=;a<C;a++)
{
LL b=C-npow(a,k1+b1,C);
LL x=npow(a,*k1+b1,C);
LL y=npow(b,k2+,C);
if((x+y)%C==)
{
tag=true;
printf("%lld %lld\n",a,b);
}
}
if(!tag)
{
printf("-1\n");
}
}
return ;
}

HDU5478(快速幂)的更多相关文章

  1. 矩阵快速幂 HDU 4565 So Easy!(简单?才怪!)

    题目链接 题意: 思路: 直接拿别人的图,自己写太麻烦了~ 然后就可以用矩阵快速幂套模板求递推式啦~ 另外: 这题想不到或者不会矩阵快速幂,根本没法做,还是2013年长沙邀请赛水题,也是2008年Go ...

  2. 51nod 算法马拉松18 B 非010串 矩阵快速幂

    非010串 基准时间限制:1 秒 空间限制:131072 KB 分值: 80 如果一个01字符串满足不存在010这样的子串,那么称它为非010串. 求长度为n的非010串的个数.(对1e9+7取模) ...

  3. hdu 4704 Sum (整数和分解+快速幂+费马小定理降幂)

    题意: 给n(1<n<),求(s1+s2+s3+...+sn)mod(1e9+7).其中si表示n由i个数相加而成的种数,如n=4,则s1=1,s2=3.                  ...

  4. Codeforces632E Thief in a Shop(NTT + 快速幂)

    题目 Source http://codeforces.com/contest/632/problem/E Description A thief made his way to a shop. As ...

  5. GDUFE-OJ 1203x的y次方的最后三位数 快速幂

    嘿嘿今天学了快速幂也~~ Problem Description: 求x的y次方的最后三位数 . Input: 一个两位数x和一个两位数y. Output: 输出x的y次方的后三位数. Sample ...

  6. 51nod 1113 矩阵快速幂

    题目链接:51nod 1113 矩阵快速幂 模板题,学习下. #include<cstdio> #include<cmath> #include<cstring> ...

  7. 【66测试20161115】【树】【DP_LIS】【SPFA】【同余最短路】【递推】【矩阵快速幂】

    还有3天,今天考试又崩了.状态还没有调整过来... 第一题:小L的二叉树 勤奋又善于思考的小L接触了信息学竞赛,开始的学习十分顺利.但是,小L对数据结构的掌握实在十分渣渣.所以,小L当时卡在了二叉树. ...

  8. HDU5950(矩阵快速幂)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5950 题意:f(n) = f(n-1) + 2*f(n-2) + n^4,f(1) = a , f(2 ...

  9. 51nod 1126 矩阵快速幂 水

    有一个序列是这样定义的:f(1) = 1, f(2) = 1, f(n) = (A * f(n - 1) + B * f(n - 2)) mod 7. 给出A,B和N,求f(n)的值. Input 输 ...

随机推荐

  1. tornado解析 第一篇

    一.tornado介绍 Tornado 是 FriendFeed 使用的可扩展的非阻塞式 web 服务器及其相关工具的开源版本.这个 Web 框架看起来有些像web.py 或者 Google 的 we ...

  2. Es6 export default 的用法

    export 之后加上default意指默认接口的意思,在一个文件里面默认的只能有一个 其区别就是{} 在export中 引入需要用{}来盛放 //这是设置入口var a='my name is xi ...

  3. 写makefile时候的cc和gcc

    Linux 下 的 cc 和 gcc     Linux 下 的 cc 和 gcc 周银辉 在Linux下一会看到cc,另一会又看到gcc,感觉又点混乱的样子.它们是同一个东西么,有啥区别呢 一分为二 ...

  4. js用星号隐藏电话中间四位号码

    $(document).ready(function(){ var mobile="{$user.mobile}"; var reg=/^(\d{3})\d{4}(\d{4})$/ ...

  5. javascript 时间日期处理相加相减

    var d = new Date("2008/04/15"); d.setMonth(d.getMonth() + 1 + 1);//加一个月,同理,可以加一天:getDate() ...

  6. hadoop环境搭建(linux单机版)

    一.在Ubuntu下创建hadoop用户组合hadoop用户 1.创建hadoop用户组      addgroup hadoop 2.创建hadoop用户      adduser -ingroup ...

  7. Office文件的实质是什么

    Office文件的实质是什么 一.总结 一句话总结:对于一个Microsoft Office文件,其实质是一个Windows复合二进制文件(Windows Compound Binary File), ...

  8. WPF各种控件详解——(WPF从我炫系列)

    http://blog.csdn.net/zx13525079024/article/details/5694638

  9. 识别设备是IOS还是安卓

    var u = navigator.userAgent; var isAndroid = u.indexOf('Android') > -1 || u.indexOf('Adr') > - ...

  10. 分布式_理论_07_ZAB

    一.前言 二.参考资料 1.分布式理论(七)—— 一致性协议之 ZAB