hdu5478 Can you find it(数学)
来源:互联网 发布:怎么样抓取精准数据库 编辑:程序博客网 时间:2024/05/01 16:11
思路:通过n=1的时候枚举a求出b,然后通过n=2的时候验证是否成立
#include<bits/stdc++.h>using namespace std;#define LL long longLL C,k1,b1,k2;LL qpow(LL x,LL n,LL mod){ LL ans=1; while(n>0) { if(n&1) ans=(ans*x)%mod; x=(x*x)%mod; n>>=1; } return ans;}int main(){ int T,cas=1; while(scanf("%lld%lld%lld%lld",&C,&k1,&b1,&k2)!=EOF) { int flag = 0; printf("Case #%d:\n",cas++); for(LL a = 1;a<C;a++) { LL b = C-qpow(a,k1+b1,C); LL x = qpow(a,2*k1+b1,C); LL y = qpow(b,k2+1,C); if((x+y)%C==0) { printf("%lld %lld\n",a,b); flag = 1; } } if(!flag) printf("-1\n"); }}
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.
Please output all pairs (a, b) in lexicographical order.
Sample Input
23 1 1 2
Sample Output
Case #1:1 22
Source
2015 ACM/ICPC Asia Regional Shanghai Online
0 0
- hdu5478 Can you find it(数学)
- hdu5478 Can you find it(数学规律)
- HDU5478 Can you find it
- hdu5478 Can you find it
- HDU5478 Can you find it 快速幂取模
- HDU5478 Can you find it (快速幂)
- hdu5478 Can you find it+快速幂
- HDU5478 Can you find it【同余问题】
- HDU5478——Can you find it(快速幂)
- can you find it?
- Can you find it?
- Can you find it?
- Can you find it?
- can you find it?
- Can you find it?
- can you find it?
- Can you find it?
- Can you find it?
- 虫部落 快搜
- c++编程题1
- 【笔记】数组
- 数据库垂直拆分 水平拆分
- Fortran含Module情况下Makefile文件书写
- hdu5478 Can you find it(数学)
- Java-NowCoder-计算字符个数
- spark mllib Matrices CSC
- 求全排列的4种情况
- hdu5476 Explore Track of Point(数学)
- 阿里笔试题
- hdu5477 A Sweet Journey(水)
- panic: reflect.Value.Interface: cannot return value obtained from unexported field or method
- C++ TCP 和 UDP 在socket编程中的区别