题目链接

根据公式

\[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. sqlserver 2008 局域网跨服务器T-SQL操作(一)

    --查看当前链接情况: select * from sys.servers; --增加链接,参数:服务器别名,为链接服务器的OLE DB数据源的产品名称,与此数据源对应的OLE DB访问接口的唯一编程 ...

  2. C# 根据年月获得此月第一天和最后一天,并计算工作日

    string str = "2015年3月"; ); ); , secondIndex - firstIndex - ); , ); DateTime dt = DateTime. ...

  3. 10个简单步骤,完全理解SQL

    此文章为转载 1. SQL 是一种声明式语言 首先要把这个概念记在脑中:“声明”. SQL 语言是为计算机声明了一个你想从原始数据中获得什么样的结果的一个范例,而不是告诉计算机如何能够得到结果.这是不 ...

  4. 解决OpenWrt多拨刚开机拨号只拨上一次问题

    红色标注为需要权限755/etc/ppp/ip-up.d/ip-up: 一旦 PPP 连结建立后, pppd 会找寻 /etc/ppp/ip-up 指令稿 如果这个指令稿存在并且可以执行的话,那么 P ...

  5. vim highlight whitespace at end of line and auto delete them

    install Vundle.vim mkdir ~/.vim/bundle git clone https://github.com/gmarik/Vundle.vim.git ~/.vim/bun ...

  6. MySql 优化 网上资料

    1.选取最适用的字段属性 MySQL可以很好的支持大数据量的存取,但是一般说来,数据库中的表越小,在它上面执行的查询也就会越快.因此,在创建表的时候,为了获得更好的性能,我们可以将表中字段的宽度设得尽 ...

  7. delete 指针

    #include<iostream>using namespace std;class human{public: human(){cout<<"构造";} ...

  8. QT5中QString与char *的相互转换

    以例子说明: #include <QApplication> #include <QDebug> #include <QString> #include <Q ...

  9. QStringList不是简单重命名的便利类,而是提供了额外的函数,比如sort和join等等

    以前一直以为就是重命名而已,原来还不是.QT真伟大,方便到家了.该有的,全都有现成的.

  10. C语言的本质(5)——类型转换的本质与处理

    数据类型转换的方式 C 语言中的数据类型转换可分为隐式转换和显式转换两种. 隐式转换 隐式转换也可称作为自动转换,它经常以以下几种形式发生: 1.在计算一个同时出现多种数据类型的表达式时,将所有数据类 ...