HDU 2685 I won't tell you this is about number theory
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2685
题意:求gcd(a^m - 1, a^n - 1) mod k
思路:gcd(a^m - 1, a^n - 1) = a^gcd(m, n) - 1
code:
#include <stdio.h> int gcd(int a, int b)
{
return !b ? a : gcd(b, a%b);
} int mod_pow(int a, int x, int mod)
{
int tmp = a;
int ret = ;
while(x) {
if (x & ) {
ret = ret * tmp % mod;
}
tmp = tmp * tmp % mod;
x >>= ;
} return ret;
} int main()
{
int t, a, m, n, k;
scanf("%d", &t);
while (t--) {
scanf("%d %d %d %d", &a, &m, &n, &k);
int d = gcd(m, n);
int ans = mod_pow(a, d, k);
printf("%d\n", (ans - + k) % k);
} return ;
}
HDU 2685 I won't tell you this is about number theory的更多相关文章
- hdu 2685 I won't tell you this is about number theory 数论
题目链接 根据公式 \[ gcd(a^m-1, a^n-1) = a^{gcd(m, n)}-1 \] 就可以很容易的做出来了. #include <iostream> #include ...
- HDU 2685 GCD推导
求$(a^n-1,a^m-1) \mod k$,自己手推,或者直接引用结论$(a^n-1,a^m-1) \equiv a^{(n,m)}-1 \mod k$ /** @Date : 2017-09-2 ...
- hdu 2685(数论相关定理+欧几里德定理+快速取模)
I won't tell you this is about number theory Time Limit: 2000/1000 MS (Java/Others) Memory Limit: ...
- HDU 1210 Eddy's 洗牌问题(foj1062) || FOJ1050 Number lengths水
麻痹,感冒了. ------------------------------------------------感冒了的分割线------------------------------------- ...
- 2018HDU多校训练-3-Problem D. Euler Function
链接:http://acm.hdu.edu.cn/showproblem.php?pid=6322 Problem Description In number theory, Euler's toti ...
- HDU 3341 Lost's revenge(AC自动机+DP)
Lost's revenge Time Limit: 15000/5000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)T ...
- HDU 3336 Count the string(KMP的Next数组应用+DP)
Count the string Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- HDU 5584 LCM Walk 数学
LCM Walk Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5584 ...
- HDU 5778 abs (枚举)
abs 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5778 Description Given a number x, ask positive ...
随机推荐
- 【线段树】【3-21个人赛】【同样的problemB】
同一道题 http://blog.csdn.net/zy691357966/article/details/44680121 区间查询最大值 用线段树 比单调队列慢 #include <cst ...
- 性能强悍的开源关系数据库PostgreSQL
性能强悍的开源关系数据库PostgreSQL
- Mysql安装时出现APPLY security settings错误
在安装mysql数据库时,如果重新安装,很容易遇见apply security setting error(access denied for user 'root@localhost'(using ...
- ChartConlrol二维图表类型
WinForms Controls >Controls > Chart Control > Concepts > Creating Charts > 2D Chart T ...
- js简易写法
我写JavaScript代码已经很久了,都记不起是什么年代开始的了.对于JavaScript这种语言近几年所取得的成就,我感到非常的兴奋:我很幸运也是这些成就的获益者.我写了不少的文章,章节,还有一本 ...
- CSS3 布局
1.1 列布局 CSS3中新出现的多列布局(multi-column)是传统HTML网页中块状布局模式的有力扩充.这种新语法能够让WEB开发人员轻松的让文本呈现多列显示.我们知道,当一行文字太长时 ...
- springmvc jstl
springmvc运用maven的jetty插件运行成功,部署在tomcat6报错:ClassNotFoundException: javax.servlet.jsp.jstl.core.Config ...
- Hql参数占位符使用(转+整理)
在Hibernate 4版本中,对于Hql有一点点改变,如果你还是按照以前的方式去编写HQL Query query = sessionFactory.openSession().createQuer ...
- send()和recv()函数详解
send()函数 int send( SOCKET s, const char FAR *buf, int len, int flags ); 不论是客户还是服务器应用程序都用send函数来向TCP连 ...
- Python 自带IDLE中调试程序
在vs2013下调试过Python,今天试了下使用自带IDLE调试,相比而言后者效果不好. 记录一下 http://q.cnblogs.com/q/35869/ 在“Python Shell”窗口中单 ...