HDU 5478 Can you find it

题意略。

思路:先求出n = 1 时候满足条件的(a,b), 最多只有20W对,然后对每一对进行循环节判断即可

 #include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <deque>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <map>
#include <stack>
#include <set>
#define LL long long
#define eps 1e-8
#define INF 0x3f3f3f3f
#define MAXN 200005
using namespace std;
LL C, k1, b1, k2;
LL quick_mod(LL x, LL y, LL mod){
if (y == ) return ;
LL res = quick_mod(x, y >> , mod);
res = res * res % mod;
if (y & ){
res = res * x % mod;
}
return res;
}
LL a[MAXN][];
LL b[MAXN];
int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
//freopen("out.txt", "w", stdout);
#endif // OPEN_FILE
int cas = ;
while (~scanf("%I64d%I64d%I64d%I64d", &C,&k1, &b1, &k2)){
printf("Case #%d:\n", cas++);
int t = ;
for (int i = ; i < C; i++){
LL m = quick_mod((LL)i, k1 + b1, C);
if (m == ) continue;
a[++t][] = i;
a[t][] = C - m;
b[t] = m;
}
bool noans = true;
for (LL i = ; i <= t; i++){
LL pa = b[i];
LL pa_k1 = quick_mod(a[i][], k1, C);
LL pb_k2 = quick_mod(a[i][], k2, C);
LL pb = a[i][];
LL xx = pa;
LL yy = pb;
// pb_k2 = quick_mod(pb_k2, 10000, C);
LL x = pa_k1, y = pb_k2;
bool flag = false;
for (int j = ; j <= ; j++){
pa = pa * x % C;
pb = pb * y % C;
if (pa == xx && pb == yy){
break;
}
if ((pa + pb) % C != ){
flag = true;
break;
}
}
if (flag) continue;
printf("%I64d %I64d\n", a[i][], a[i][]);
noans = false;
}
if (noans){
printf("-1\n");
}
}
}

最新文章

  1. NOIp 2006 作业调度方案 Label:坑 模拟(tyvj你不给我ac,我就把名字献给附中oj)
  2. C中的基本数据类型和变量
  3. 剑指offer系列41---数字在数组中出现的次数
  4. Windows 7 不同安装模式简要区别(图解)
  5. Win7构造wifi热点【Written By KillerLegend】
  6. Unable to create the store directory. (Exception from HRESULT: 0x80131468)
  7. Spring Framework 中启动 Redis 事务操作
  8. 内核参数优化之1 keepalive解析
  9. 自制单片机之十二……AT89C2051烧写器的制做与调试
  10. Get Start StrangeIOC for Unity3D
  11. jQuery切换网页皮肤并保存到Cookie示例代码
  12. Install a Jenkins on Ubuntu system
  13. SharePoint 2013 页面访问,Url中间多一段&amp;quot;_layouts/15/start.aspx#&amp;quot;
  14. Spring中你可能不知道的事(一)
  15. php扩展打开不起作用的原因, php数字显示2147483647的原因
  16. Ubuntu 16.04 上安装 PCL 1.8.0
  17. C#格式规范
  18. 100以内奇偶数(for循环)
  19. Unity3d之截图方法
  20. POJ 3903 Stock Exchange(LIS || 线段树)题解

热门文章

  1. Linux 添加挂载硬盘(包含挂载大于2T以上硬盘)
  2. Adobe Flex迷你教程 —Flex4全屏显示
  3. HDU——T 1507 Uncle Tom&#39;s Inherited Land*
  4. 洛谷——P1455 搭配购买
  5. BZOJ 1088 水模拟
  6. UVa 10954 Add All 贪心
  7. [P3097] [USACO13DEC] [BZOJ4094] 最优挤奶Optimal Milking 解题报告(线段树+DP)
  8. Android控件postDelayed用法,View自带的定时器
  9. ES6中includes、startsWith、endsWith
  10. hdu 1022 - 数据结构 栈