题目链接

根据公式

\[gcd(a^m-1, a^n-1) = a^{gcd(m, n)}-1
\]

就可以很容易的做出来了。

#include <iostream>
#include <vector>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <complex>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <queue>
#include <stack>
#include <bitset>
using namespace std;
#define pb(x) push_back(x)
#define ll long long
#define mk(x, y) make_pair(x, y)
#define lson l, m, rt<<1
#define mem(a) memset(a, 0, sizeof(a))
#define rson m+1, r, rt<<1|1
#define mem1(a) memset(a, -1, sizeof(a))
#define mem2(a) memset(a, 0x3f, sizeof(a))
#define rep(i, n, a) for(int i = a; i<n; i++)
#define fi first
#define se second
typedef complex <double> cmx;
typedef pair<int, int> pll;
const double PI = acos(-1.0);
const double eps = 1e-8;
const int mod = 1e9+7;
const int inf = 1061109567;
const int dir[][2] = { {-1, 0}, {1, 0}, {0, -1}, {0, 1} };
int gcd(int a, int b) {
return b?gcd(b, a%b):a;
}
int pow(int a, int b, int k) {
int tmp = 1;
while(b) {
if(b&1) {
tmp = tmp*a%k;
}
a = a*a%k;
b>>=1;
}
return tmp;
}
int main()
{
int t;
cin>>t;
while(t--) {
int a, k, m, n;
scanf("%d%d%d%d", &a, &m, &n, &k);
int tmp = gcd(m, n);
tmp = pow(a, tmp, k);
tmp = (tmp-1+k)%k;
printf("%d\n", tmp);
}
return 0;
}

hdu 2685 I won't tell you this is about number theory 数论的更多相关文章

  1. 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, ...

  2. 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 ...

  3. HDU 1005 Number Sequence(数论)

    HDU 1005 Number Sequence(数论) Problem Description: A number sequence is defined as follows:f(1) = 1, ...

  4. hdu 2685(数论相关定理+欧几里德定理+快速取模)

    I won't tell you this is about number theory Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: ...

  5. HDU 1210 Eddy's 洗牌问题(foj1062) || FOJ1050 Number lengths水

    麻痹,感冒了. ------------------------------------------------感冒了的分割线------------------------------------- ...

  6. HDU 5166 Missing number 简单数论

    Missing number Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) [ ...

  7. hdu 4279"Number"(数论)

    传送门 参考资料: [1]:https://www.2cto.com/kf/201308/233613.html 题意,题解在上述参考资料中已经介绍的非常详细了,接下来的内容只是记录一下我的理解: 我 ...

  8. HDU 1018 Big Number(数论,Stirling公式)

    1. 利用数学公式lg(n!)=lg(2)+lg(3)+....+lg(n) 求解 2.

  9. 2018HDU多校训练-3-Problem D. Euler Function

    链接:http://acm.hdu.edu.cn/showproblem.php?pid=6322 Problem Description In number theory, Euler's toti ...

随机推荐

  1. codevs1387

    题目描述                     Description 一块N x N(1<=N<=10)正方形的黑白瓦片的图案要被转换成新的正方形图案.写一个程序来找出将原始 图案按照 ...

  2. jsoup 解析html 页面数据

    我html 页面元素: /html/body/table[2]/tbody/tr[1]/td/table/tbody/tr[1]/td[2]/font/html/body/table[2]/tbody ...

  3. Python 入门之常见小问题

    1.在终端运行python,出现>>>即可输入代码回车进行执行,如果要退出,只需要执行exit()即可. -->在Python交互式命令行下,可以直接输入代码,然后执行,并立刻 ...

  4. Android 开源控件系列_2

    FileBrowserView 一个强大的文件选择控件.界面比较漂亮,使用也很简单.特点:可以自定义UI:支持复制.剪切.删除.移动文件:可以用在Fragment.ativity.DialogFrag ...

  5. 《UNIX网络编程》TCP客户端服务器:并发、消息回显

    经过小小改动,把前面基础的例子做出一点修改. 并发服务器,服务器每accept一个请求就fork()一个新的子进程. 编译运行方法同前一篇. /*client_tcp.c*/ #include < ...

  6. Diet

    Dialogue 1   Healthy diet 关于健康饮食 F:Bob, look at this sentence. 'Healthy eating is not about strict n ...

  7. 如何用ATL创建ActiveX控件

    演示截图: 代码简介或代码解析: 如何用ATL创建ActiveX控件 实现了一个ActiveX控件,它在一个圆内部有个正多边形,当用户在多变形内部单击将会使多边形的边数在当前的基础上+1,在多变形外部 ...

  8. HTML5 javascript实现音乐播放器

    准备毕业了,感觉好多东西都没学会,太多太多想学的知识,有种求知若渴的状态. 四年的大学就剩下一个多月了,无论将来多么困难,这条路是自己选的,走就要走的精彩! 自学了一点javascript.php,做 ...

  9. AndroidUI 视图动画-透明动画效果 (AlphaAnimation)

    1.新建一个Android项目,Activity添加一个按钮如下代码: <Button android:id="@+id/btnAiphaAnimation" android ...

  10. SSH登陆服务器的简单命令

    SSh 用户名@目标Ip: 回车输入密码: