UVaLive 7457 Discrete Logarithm Problem (暴力)
题意:求一个x使得 a^x%p = b p为素数;
析:从1开始扫一下就好,扫到p-1就可以了,关键是这个题为什么要用文件尾结束,明明说是0,但是不写就WA。。。
代码如下:
- #pragma comment(linker, "/STACK:1024000000,1024000000")
- #include <cstdio>
- #include <string>
- #include <cstdlib>
- #include <cmath>
- #include <iostream>
- #include <cstring>
- #include <set>
- #include <queue>
- #include <algorithm>
- #include <vector>
- #include <map>
- #include <cctype>
- #include <cmath>
- #include <stack>
- #define freopenr freopen("in.txt", "r", stdin)
- #define freopenw freopen("out.txt", "w", stdout)
- using namespace std;
- typedef long long LL;
- typedef pair<int, int> P;
- const int INF = 0x3f3f3f3f;
- const double inf = 0x3f3f3f3f3f3f;
- const LL LNF = 0x3f3f3f3f3f3f;
- const double PI = acos(-1.0);
- const double eps = 1e-8;
- const int maxn = 1e3 + 100;
- const int mod = 1e9 + 7;
- const int dr[] = {-1, 0, 1, 0};
- const int dc[] = {0, 1, 0, -1};
- const char *Hex[] = {"0000", "0001", "0010", "0011", "0100", "0101", "0110", "0111", "1000", "1001", "1010", "1011", "1100", "1101", "1110", "1111"};
- int n, m;
- const int mon[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
- const int monn[] = {0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
- inline int Min(int a, int b){ return a < b ? a : b; }
- inline int Max(int a, int b){ return a > b ? a : b; }
- inline LL Min(LL a, LL b){ return a < b ? a : b; }
- inline LL Max(LL a, LL b){ return a > b ? a : b; }
- inline bool is_in(int r, int c){
- return r >= 0 && r < n && c >= 0 && c < m;
- }
- int solve(int a, int b, int m){
- int x = a;
- for(int i = 1; i < m; ++i){
- if(x == b) return i;
- x = (x * a) % m;
- }
- return 0;
- }
- int main(){
- int r, m, a;
- scanf("%d", &m);
- while(scanf("%d", &a) == 1){
- if(!a) break;
- scanf("%d", &r);
- int ans = solve(a, r%m, m);
- printf("%d\n", ans);
- }
- return 0;
- }
UVaLive 7457 Discrete Logarithm Problem (暴力)的更多相关文章
- UVALive 7457 Discrete Logarithm Problem (暴力枚举)
Discrete Logarithm Problem 题目链接: http://acm.hust.edu.cn/vjudge/contest/127401#problem/D Description ...
- 证明与计算(2): 离散对数问题(Discrete logarithm Problem, DLP)
离散对数问题,英文是Discrete logarithm Problem,有时候简写为Discrete log,该问题是十几个开放数学问题(Open Problems in Mathematics, ...
- 2019杭电多校第五场 discrete logarithm problem
https://vjudge.net/contest/317493#problem/I
- 2019牛客多校第二场F Partition problem 暴力+复杂度计算+优化
Partition problem 暴力+复杂度计算+优化 题意 2n个人分成两组.给出一个矩阵,如果ab两个在同一个阵营,那么就可以得到值\(v_{ab}\)求如何分可以取得最大值 (n<14 ...
- UVALive 7070 The E-pang Palace 暴力
The E-pang Palace Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/problem ...
- hdu 3699 10 福州 现场 J - A hard Aoshu Problem 暴力 难度:0
Description Math Olympiad is called “Aoshu” in China. Aoshu is very popular in elementary schools. N ...
- Codeforces Round #127 (Div. 1) D. Brand New Problem 暴力dp
D. Brand New Problem 题目连接: http://www.codeforces.com/contest/201/problem/D Description A widely know ...
- Codeforces:68A-Irrational problem(暴力大法好)
A- Irrational problem p Time Limit: 2000MS Memory Limit: 262144K 64bit IO Format: %I64d& %I64 De ...
- Codeforces Beta Round #17 A - Noldbach problem 暴力
A - Noldbach problem 题面链接 http://codeforces.com/contest/17/problem/A 题面 Nick is interested in prime ...
随机推荐
- Weblogic调优
优化说明: 一.Weblogic服务程序设置: 1.设置JDK内存: 修改weblogic\user_projects\domains\base_domain\bin下的setDomainEnv.cm ...
- [HTML5] Show Images of Differing Resolutions Depending on the Viewport Width with srcset
For small viewports, we want to save bandwidth and we may be dealing with slow speeds; so it's very ...
- hadoop-mapreduce中reducetask执行分析
ReduceTask的执行 Reduce处理程序中须要运行三个类型的处理, 1.copy,从各map中copy数据过来 2.sort,对数据进行排序操作. 3.reduce,运行业务逻辑的处理. Re ...
- C#中Queue<T>类的使用以及部分方法的源代码分析
Queue<T>类 表示对象的先进先出集合. 队列在按接收顺序存储消息方面很实用,以便于进行顺序处理. 存储在 Queue,<T> 中的对象在一端插入,从还有一端移除. Que ...
- VBscript 做的设置网卡名称
Set WSHShell=WScript.CreateObject("WScript.Shell") Dim NetcardDescriptionDim NetcardName i ...
- HTML URL编码规则
将空格转换为加号(+) 对0-9,a-z,A-Z之间的字符保持不变 对于所有其他的字符,用这个字符的当前字符集编码在内存中的十六进制格式表示,并在每个字节前加上一个百分号(%).如字符“+”用%2B表 ...
- php中的register_shutdown_function和fastcgi_finish_request
在php中又两个方法都是在请求快结束的时候执行.方法名分别是 register_shutdown_function和fastcgi_finish_request.虽然执行的时机差不多,但是功能和应用场 ...
- javascript 总结(持续更新)
1.jQuery对象转DOM对象. jQuery对象转DOM对象有两种方法,[index]和get(index). var $cr = $("#cr"); //jQuery对象 v ...
- XenServer网卡Bonding
在给XenServer配置网卡bonding时,需要在所有节点都添加到集群之后再进行,这也是来自Citrix的建议:"Citrix recommends never joining a ho ...
- 下载Google官方/CM Android源码自己主动又一次開始的Shell脚本
国内因为某种原因,下载CM或Google官方的Android源码总easy中断.总看着机器.一中断就又一次运行repo sync还太麻烦,所以我特意编写了一段shell脚本(download.sh). ...