hdoj 5478 Can you find it
2015-09-26 21:06
357 查看
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, ...).
枚举a,把n=1代入,算出b。根据a,b,代入n=2,如果等式成立,就输出。
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, ...).
枚举a,把n=1代入,算出b。根据a,b,代入n=2,如果等式成立,就输出。
#include <iostream> using namespace std; #define ll long long const int maxn = 100010; ll c,k1,B1,k2; ll p; ll Quick_Pow(ll a,ll n) { ll ret=1; ll temp=a%p; while (n){ if (n&1) ret=ret*temp%p; temp=temp*temp%p; n>>=1; } return ret; } int main(){ int cas = 0; while(cin>>c>>k1>>B1>>k2){ cas++; printf("Case #%d:\n",cas); bool hassol=0; for(int a=1;a<c;a++){ //a^(k1*n+b1) //b^(k2*n-k2+1) p=c; ll a1 = Quick_Pow(a,k1+B1); ll b = c - a1; bool ok=1; ll an=a1; ll bn=b; ll atmp = Quick_Pow(a,k1); ll btmp = Quick_Pow(b,k2); an*=atmp; bn*=btmp; an%=c; bn%=c; if( (an+bn)%c==0 ){ hassol=1; printf("%I64d %I64d\n",a,b); } } if(!hassol){ printf("-1\n"); } } return 0; }
相关文章推荐
- [Qt] Mask 蒙版
- 黑马程序员-----java基础(网络编程)
- 【今日推荐】10大流行的 Metro UI 风格的 Bootstrap 主题和模板
- JavaScript高级程序设计之引用类型之RegExp 类型第5.4讲笔记
- JSP编码问题
- CodeVS1513 皇帝的烦恼
- LeetCode——Ugly Number
- [Qt] Mask 蒙版
- Learning Spark - LIGHTNING-FAST DATA ANALYSIS 第三章 - (3)
- 【转】电子商务网站测试经验总结
- 系统性能指标
- 2015 ACM/ICPC Asia Regional Shanghai Online
- Android中的Touch事件处理流程
- TCP成块数据流
- [Qt] searchBox 搜索框实现
- Linux驱动知识点汇总
- 杭电acm--2024
- c++设计模式-----中介者模式Mediator
- opengl glBegin() glEnd() 中常用函数
- 瞬时动作的函数