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(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.

Examples

Input

23 1 1 2

Output

Case #1:
1 22

题意:给出一个质数 c,三个正整数 k1,b1,k2,对于公式 ,若能找出最小的 a,b 则输出,若找不出则输出 -1

思路:公式题

对于公式 

当 n=1 时, ①

当 n=2 时, ②

令  * ②, ③

令 ③-②,

即:

由于 a、b < c,只需要枚举 a 的值(1~c-1),通过快速幂计算 ,从而算出 b,再求出 ,比较  是否等于  即可

Source Program

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<cstring>
#include<cmath>
#include<ctime>
#include<algorithm>
#include<utility>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<map>
#define PI acos(-1.0)
#define E 1e-6
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define N 500001
#define LL long long
using namespace std;
LL Pow_Mod(LL a, LL b, LL m)
{LL res=1;while(b){if(b&1)res=(res*a)%m;a=(a*a)%m;b>>=1;}return res;
}int main(){LL c,k1,b1,k2;int Case=1;while(scanf("%lld%lld%lld%lld",&c,&k1,&b1,&k2)!=EOF){bool flag=false;printf("Case #%d:\n",Case++);for(LL i=1;i<=c-1;i++){LL a=Pow_Mod(i,k1,c);LL b=c-Pow_Mod(i,k1+b1,c);LL temp=Pow_Mod(b,k2,c);if(a==temp){flag=true;printf("%lld %lld\n",i,b);}}if(!flag)printf("-1\n");}return 0;
}

Can you find it(HDU-5478)相关推荐

  1. 有源汇有上下界最大流/最小流 配题(HDU 3157)

    因为是有源汇所以设源点为 s,汇点为 t. 有源汇有上下界最大流: 连接一条 t 指向 s 的边,容量为 INF. 通过上述步骤,现在图变成了无源汇网络. 引入超级源点 S,超级汇点 T. 连接一条 ...

  2. 最大表示法--环形字符串最大字典序(HDU 5442)

    http://acm.hdu.edu.cn/showproblem.php?pid=5442 问题概述:n个字符围成一个环,请从这个环中找出字典序最大的长度为n的字符串,输出它的起始点和方向(0顺1 ...

  3. HDU2019多校第二场 1009(HDU 6599) I Love Palindrome String(回文树(自动机)+manacher)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6599 解题思路: 回文自动机求每个本质不同的子串出现的次数,同时记录每个节点i代表的回文串第一次出现的 ...

  4. S-Nim (HDU 1536)组合博弈SG多组游戏

    S-Nim 题目链接 Problem Description Arthur and his sister Caroll have been playing a game called Nim for ...

  5. BestCoder25 1001.Harry and Magical Computer(hdu 5154) 解题报告

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5154 题目意思:有 n 门 processes(编号依次为1,2,...,n),然后给出 m 种关系: ...

  6. (HDU - 1847)Good Luck in CET-4 Everybody!(博弈)

    题目链接:Good Luck in CET-4 Everybody! - HDU 1847 - Virtual Judge (ppsucxtt.cn) 题目是中文的,我在这就不翻译题意了. 先说一种打 ...

  7. 美素数(HDU 4548)(打表,简化时间复杂度)

    相信大家都喜欢美的东西,让我们一起来看看美素数吧. 问题是这样的:一个十进制数,如果是素数,而且它的各位数字和也是素数,则称之为"美素数",如29,本身是素数,而且2+9 = 11 ...

  8. 单词数(HDU 2072)

    lily的好朋友xiaoou333最近很空,他想了一件没有什么意义的事情,就是统计一篇文章里不同单词的总数.下面你的任务是帮助xiaoou333解决这个问题. Input 有多组数据,每组一行,每组就 ...

  9. Ant Trip(HDU 3018)---多笔画问题

    题目链接 题目描述 Ant Country consist of N towns.There are M roads connecting the towns. Ant Tony,together w ...

  10. 机器人的舞蹈(hdu 2232)

    机器人的舞蹈 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Sub ...

最新文章

  1. asp.net web forms page life cycle
  2. 一起谈.NET技术,在Mono 2.8上部署ASP.NET MVC 2
  3. jQuery美化select下拉框
  4. 华南师范大学计算机学院重修,为什么说本科绩点低毁一生 大学重修可以刷绩点吗...
  5. { parser: babylon } is deprecated; we now treat it as { parser: babel }.
  6. 去哪儿-13-city-vuex
  7. 初级黑客安全技术命令详解
  8. 二进制安装 kubernetes 1.12(四) - 部署 Node 节点组件
  9. [搬家]新域名 akagi201.org
  10. Spring源码之bean的加载(一)
  11. k2p华硕系统怎么设置_斐讯k2华硕固件,斐讯k2p华硕固件设置
  12. 大学 计算机 试题,【分享】《大学计算机基础》试题题库及答案 ~~~~~~~~~~~...
  13. 很抱歉,三维地图当前不能在你的国家/地区使用 Excel绘制三维地图问题解决
  14. 【工具】D2RQ安装和配置
  15. Python | 小白的 Asyncio 教程
  16. 微信竟可以查出行轨迹了,预计又一波情侣要分手?
  17. 第一次谈兼职写书的经过
  18. netkeeper不能建立远程计算机连接,Netkeeper客户端常见问题集锦.doc
  19. 使用 acme.sh 签发 SSL证书失败
  20. Photoshop数码艺术照片合成处理视频教程

热门文章

  1. 没看过这5本硬核技术书,就别说你懂大数据
  2. 人工智能先驱 Nils Nilsson 去世,吴恩达、Yann LeCun 悼念
  3. 为什么美团全面推动 K8S 落地,咬紧牙关也要搞云原生?
  4. 马化腾生日当天 微信支付居然崩溃了//(ㄒoㄒ)//
  5. jeecg开源社区近期版本发布计划
  6. bindService过程
  7. MYSQL GROUP BY 对多个字段进行分组
  8. QQ音乐:React v16 新特性实践
  9. 重定向 302 与localhost 学习笔记
  10. 使用protostuff进行序列化