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. 通过加载Xib文件来创建UITableViewCell造成复用数据混乱问题方案

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPa ...

  2. /var/spool/clientmqueue 爆满问题

    当你使用简单的sendmail发邮件的时候,或者系统默认要发一些邮件(比如cron发的邮件)的时候,首先会把邮件拷贝到这个目录里,然后等待MTA(mail transfer agent) 来处理,MT ...

  3. Servlet和Filter的url匹配以及url-pattern详解

    Servlet和filter是J2EE开发中常用的技术,使用方便,配置简单,老少皆宜.估计大多数朋友都是直接配置用,也没有关心过具体的细节,今天遇到一个问题,上网查了servlet的规范才发现,ser ...

  4. mysql基础(5)-关联(mysql+pandas)

    表关联类型 内连接: 仅显示满足条件的行 From T1,T2 where T1.ID=T2.ID From T1 inner join T2 ON T1.ID=T2.ID 左连接: 显示左表T1中的 ...

  5. UVA 11186 Circum Triangle (枚举三角形优化)(转)

    题意:圆上有n个点,求出这n个点组成的所有三角形的面积之和 题解: 当我们要求出S(i,j,k)时,我们需要假设k在j的左侧,k在i与j之间,k在i的右侧. 如果k在 j的左侧  那么 S(i,j,k ...

  6. 回溯法之k着色问题

    package main import ( "fmt" ) type Graphic struct { edges [][]int colors int color []int f ...

  7. 在物理机安装CentOS6.5

    这两天就要开始在用户的新服务器上部署生产环境了.之前一直都是在服务器上搭虚拟机,而在物理机上安装还是第一次. 首先是要准备启动程序.我用的U盘作为启动盘. 刻盘的操作参考 http://jingyan ...

  8. hdoj1003--Max Sum

    Problem Description Given a sequence a[1],a[2],a[3]......a[n], your job is to calculate the max sum ...

  9. js的介绍

    需要了解的 如果没有宽带产业的发展,即便是发送JSON这种轻量级数据所带来的延时成本也是不可想象的. 如果没有ECMA-262这份标准文档,各大浏览器在客户端的表现完全不一致,我们就没有办法对Web应 ...

  10. 0.00-050613_Makefile

    # Makefile for the simple example kernel. AS86 =as86 -0 -a LD86 =ld86 -0 AS =gas LD =gld LDFLAGS =-s ...