Can you find it

Time Limit: 8000/5000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 450    Accepted Submission(s): 208

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
 
Source
 
Recommend
hujie
 
 
首先想n为1,2,3……都要成立,所以先保证n=1成立,然后验证其他是否成立,把等式左边的b那一项移到右边,除一下,发现每次增量都是a^k1 和b^k2 所以只要n=2成立,后面的都成立。
下回这种题不要怕,还是可以做的。
 
#include<queue>
#include<math.h>
#include<stdio.h>
#include<string.h>
#include<string>
#include<iostream>
#include<algorithm>
using namespace std;
#define N 1234567
#define M 12
int c, k1, b1, k2;
bool flag;
int quickpow(int m,int n,int k)// m^n % k
{
int b = ;
while (n > )
{
if (n & )
b = (b*m)%k;
n = n >> ;
m = (m*m)%k;
}
return b;
}
int main()
{
int tt = ; int b;
while(~scanf("%d %d %d %d", &c, &k1, &b1, &k2))
{ printf("Case #%d:\n", tt++);
flag = ;
for(int a = ; a < c; a++)
{
b = c - quickpow(a,k1+b1,c);
if( ( quickpow(a, k1*+b1, c) + quickpow(b, k2*-k2+, c) ) %c == )
{
printf("%d %d\n",a,b);
flag = ;
}
}
if(flag == )
printf("-1\n");
}
return ;
}

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 5478 Can you find it 随机化 数学

    Can you find it Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pi ...

  3. HDU 5478 Can you find it(快速幂)

    Problem Description Given a prime number C(1≤C≤2×105), and three integers k1, b1, k2 (1≤k1,k2,b1≤109 ...

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

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

  5. hdu 5478 (数论)

    ⋅n+b1⋅n−k2+1 = 0 (mod C)(n = 1, 2, 3, ...)  (1<=a, b <C) 1.  当n = 1时, a^(k1+b1) + b = 0 ( mod ...

  6. HDOJ 2111. Saving HDU 贪心 结构体排序

    Saving HDU Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  7. 【HDU 3037】Saving Beans Lucas定理模板

    http://acm.hdu.edu.cn/showproblem.php?pid=3037 Lucas定理模板. 现在才写,noip滚粗前兆QAQ #include<cstdio> #i ...

  8. hdu 4859 海岸线 Bestcoder Round 1

    http://acm.hdu.edu.cn/showproblem.php?pid=4859 题目大意: 在一个矩形周围都是海,这个矩形中有陆地,深海和浅海.浅海是可以填成陆地的. 求最多有多少条方格 ...

  9. HDU 4569 Special equations(取模)

    Special equations Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u S ...

随机推荐

  1. redis 内存管理与数据淘汰机制(转载)

    原文地址:http://www.jianshu.com/p/2f14bc570563?from=jiantop.com 最大内存设置 默认情况下,在32位OS中,Redis最大使用3GB的内存,在64 ...

  2. 【01】webpack的安装过程截图

    [05](moyu:最好安装在C盘.默认的安装地址.) []全局安装 01,首先要安装Node.js, Node.js 自带了软件包管理器 npm. 02,Webpack 需要 Node.js v0. ...

  3. luogu2216 [HAOI2007]理想的正方形

    先对于每一行中长度为 n 的列用单调队列搞出它们的最小/大值,再将这些长度为 n 的列想象成点再对行跑一遍 #include <iostream> #include <cstring ...

  4. 六 、harbor使用

    1 登录harbor docker login 10.1.2.6 2 打上标签 docker tag e3a875d407cf 10.1.2.6/library/ctf3:xss01 3 push到h ...

  5. 新技术---- MongoDB

    MongoDB 在 CentOS7 上安装 MongoDB-------https://www.linuxidc.com/Linux/2016-06/132675.htm Centos7 安装mong ...

  6. liunx 根目录介绍

    1. /bin binary二进制 存放系统许多可执行程序文件 执行的相关指令,例如ls pwd whoami,后台的支持文件目录 2. /sbin super binary超级的二进制 存放系统许多 ...

  7. 【bzoj3231】[Sdoi2008]递归数列 矩阵乘法+快速幂

    题目描述 一个由自然数组成的数列按下式定义: 对于i <= k:ai = bi 对于i > k: ai = c1ai-1 + c2ai-2 + ... + ckai-k 其中bj和 cj  ...

  8. 【Luogu】P3391文艺平衡树(Splay)

    题目链接 ddosvoid和自为风月马前卒教了我这道题 他们好强啊 如果我们要反转区间[l,r] 我们首先把l的前驱旋转到根节点 再把r的后继旋转到根节点的右儿子 那么此时根节点的右儿子的左儿子所代表 ...

  9. angular父子scope之间的访问

    1.子可以访问父的scope,也可以更新相同的scope,但父scope不会被刷新 2.父要访问子scope的方法

  10. 维修队列(bzoj 1500)

    Description Input 输入的第1 行包含两个数N 和M(M ≤20 000),N 表示初始时数列中数的个数,M表示要进行的操作数目.第2行包含N个数字,描述初始时的数列.以下M行,每行一 ...