Can you find it

Time Limit: 1 Sec

Memory Limit: 256 MB

题目连接

http://acm.hdu.edu.cn/showproblem.php?pid=5478

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

HINT

题意

问你有多少对数,满足a^(k1⋅n+b1) + b^(k2⋅n−k2+1) = 0 (mod C)

题解:

首先你要知道,对于每个a只有唯一对应的b可以满足这个式子,因为当n=1的时候,a^(k1+b1)+b = kk*C

由于b是小于c的,所以只有一个

所以我们可以求出b来,然后我们怎么check这个b究竟是不是呢?

随机化10个数,然后随便check就好了

代码:

  1. //qscqesze
  2. #pragma comment(linker, "/STACK:1024000000,1024000000")
  3. #include <cstdio>
  4. #include <cmath>
  5. #include <cstring>
  6. #include <ctime>
  7. #include <iostream>
  8. #include <algorithm>
  9. #include <set>
  10. #include <bitset>
  11. #include <vector>
  12. #include <sstream>
  13. #include <queue>
  14. #include <typeinfo>
  15. #include <fstream>
  16. #include <map>
  17. #include <stack>
  18. typedef long long ll;
  19. using namespace std;
  20. //freopen("D.in","r",stdin);
  21. //freopen("D.out","w",stdout);
  22. #define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
  23. #define maxn 100006
  24. #define mod 1000000007
  25. #define eps 1e-9
  26. #define e exp(1.0)
  27. #define PI acos(-1)
  28. const double EP = 1E- ;
  29. int Num;
  30. //const int inf=0x7fffffff;
  31. const ll inf=;
  32. inline ll read()
  33. {
  34. ll x=,f=;char ch=getchar();
  35. while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
  36. while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
  37. return x*f;
  38. }
  39. //*************************************************************************************
  40.  
  41. ll fMul(int m,ll n,int k)
  42. {
  43. ll cc = m;
  44. ll b = ;
  45. while (n > )
  46. {
  47. if (n & 1LL)
  48. {
  49. b = (b*cc);
  50. if(b>=k)
  51. b%=k;
  52. }
  53. n = n >> 1LL ;
  54. cc = (cc*cc)%k;
  55. if(cc>=k)cc%=k;
  56. }
  57. return b;
  58. }
  59. int main()
  60. {
  61. //freopen("out.txt","r",stdin);
  62. //freopen("out2.txt","w",stdout);
  63. srand(time(NULL));
  64. int tot = ;
  65. int c ,k1 ,b1 ,k2;
  66. while(scanf("%d%d%d%d",&c,&k1,&b1,&k2)!=EOF)
  67. {
  68. printf("Case #%d:\n",tot++);
  69. int flag1 = ;
  70. for(int i=;i<c;i++)
  71. {
  72. int j=c-fMul(i,k1*+b1,c);
  73. int flag = ;
  74. for(int k=;k<=;k++)
  75. {
  76. ll tt = rand()%c+;
  77. ll ttt1 = k1, ttt2 = k2,ttt3 = b1;
  78. if((fMul(i,ttt1*tt+ttt3,c)+fMul(j,ttt2*tt-ttt2+1LL,c))%c!=)
  79. {
  80. flag = ;
  81. break;
  82. }
  83. }
  84. if(flag)
  85. {
  86. printf("%d %d\n",i,j);
  87. flag1=;
  88. }
  89. }
  90. if(!flag1)
  91. printf("-1\n");
  92. }
  93. }

HDU 5478 Can you find it 随机化 数学的更多相关文章

  1. 2015上海网络赛 HDU 5478 Can you find it 数学

    HDU 5478 Can you find it 题意略. 思路:先求出n = 1 时候满足条件的(a,b), 最多只有20W对,然后对每一对进行循环节判断即可 #include <iostre ...

  2. HDU 5073 Galaxy (2014 Anshan D简单数学)

    HDU 5073 Galaxy (2014 Anshan D简单数学) 题目链接http://acm.hdu.edu.cn/showproblem.php?pid=5073 Description G ...

  3. HDU 5478 Can you find it(数学问题)

    题目大意: 给你  ak1⋅n+b1+ bk2⋅n−k2+1 = 0 (mod C)(n = 1, 2, 3, ...). 要求所有的n都满足上述的式子. 问这样的a,b 有多少对?   分析这个问题 ...

  4. hdu 4739 Zhuge Liang's Mines 随机化

    Zhuge Liang's Mines Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.p ...

  5. HDU 2080 夹角有多大II (数学) atan(y/x)分类求角度

    夹角有多大II Problem Description 这次xhd面临的问题是这样的:在一个平面内有两个点,求两个点分别和原点的连线的夹角的大小.注:夹角的范围[0,180],两个点不会在圆心出现. ...

  6. HDU 2050 【dp】【简单数学】

    题意: 中文. 思路: 不难发现数学规律是这样的,每次增加的划分区域的数量是每次增加的交点的数量再加一.然后就总结出了递推公式. #include<stdio.h> ]; int main ...

  7. 题解报告:hdu 1284 钱币兑换问题(简单数学orDP)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1284 Problem Description 在一个国家仅有1分,2分,3分硬币,将钱N兑换成硬币有很 ...

  8. HDU 5063 Operation the Sequence(暴力 数学)

    题目链接:pid=5063" target="_blank">http://acm.hdu.edu.cn/showproblem.php?pid=5063 Prob ...

  9. HDU 6242 Geometry Problem(计算几何 + 随机化)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6242 思路:当 n == 1 时 任取一点 p 作为圆心即可. n >= 2 && ...

随机推荐

  1. MAX-HEAPIFY(2/3n的疑惑)

    Q: In CLRS, third Edition, on page 155, it is given that in MAX-HEAPIFY, The children’s subtrees eac ...

  2. 使用JRockit进行性能优化一:环境搭建

    1. jrockit简介   jrockit前身是BA jrockit,后被oracle收购,并免费发布,但并不开源.   jrockit可以看做是兼容标准的JDK基础上的JVM,同原有的JVM相比, ...

  3. windows ssh RPi 2B

    /************************************************************************* * windows ssh RPi 2B * 声明 ...

  4. Go语言项目的错误和异常管理 via 达达

    Go语言项目的错误和异常管理 最近连续遇到朋友问我项目里错误和异常管理的事情,之前也多次跟团队强调过错误和异常管理的一些概念,所以趁今天有动力就赶紧写一篇Go语言项目错误和异常管理的经验分享. 首先我 ...

  5. 【转】Linux(Ubuntu)下面SecureCRT 完全破解

    仅供测试, 勿用作商业用途.首先要到vandyke网站下载一个securecrt, 需要注册.http://www.vandyke.com/download/securecrt/download.ht ...

  6. sublime3安装python插件 -- SublimeCodeIntel

    先装Package Control,类似pip的一个索引安装工具. 1.http://sublime.wbond.net/Package%20Control.sublime-package 2.sub ...

  7. Java8 Stream API

    Stream是Java8中,操作集合的一个重要特性. 从iteration到Stream操作 当你操作一个集合的时候,你通常的做法是迭代每一个元素,然后处理你想要的事情.举个例子: String co ...

  8. 房租管理小软件(四):对linq的使用

    1.对LInq的封装如下: private static System.Data.Linq.Mapping.MappingSource mappingSource = new AttributeMap ...

  9. 设计模式_Proxy_代理模式

    形象例子: 跟MM在网上聊天,一开头总是“hi,你好”,“你从哪儿来呀?”“你多大了?”“身高多少呀?”这些话,真烦人,写个程序做为我的Proxy吧,凡是接收到这些话都设置好了自动的回答,接收到其他的 ...

  10. Ajax解决缓存的5种方法

    原文:http://www.ido321.com/129.html 1.在ajax发送请求前加上 anyAjaxObj.setRequestHeader(“If-Modified-Since”,”0″ ...