hdu 2685 I won't tell you this is about number theory 数论
题目链接
根据公式
\]
就可以很容易的做出来了。
#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 数论的更多相关文章
- 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, ...
- 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 1005 Number Sequence(数论)
HDU 1005 Number Sequence(数论) Problem Description: A number sequence is defined as follows:f(1) = 1, ...
- 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水
麻痹,感冒了. ------------------------------------------------感冒了的分割线------------------------------------- ...
- HDU 5166 Missing number 简单数论
Missing number Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) [ ...
- hdu 4279"Number"(数论)
传送门 参考资料: [1]:https://www.2cto.com/kf/201308/233613.html 题意,题解在上述参考资料中已经介绍的非常详细了,接下来的内容只是记录一下我的理解: 我 ...
- HDU 1018 Big Number(数论,Stirling公式)
1. 利用数学公式lg(n!)=lg(2)+lg(3)+....+lg(n) 求解 2.
- 2018HDU多校训练-3-Problem D. Euler Function
链接:http://acm.hdu.edu.cn/showproblem.php?pid=6322 Problem Description In number theory, Euler's toti ...
随机推荐
- ViewState存储到服务器
把viewstate保存在服务器上 将ViewState持久化保持在服务器端的代码,这样ViewState不占用网络带宽,因此其存取只是服务器的磁盘读取时间.并且它很小,可以说是磁盘随便转一圈就能同时 ...
- oracle操作语句
Oracle中建立索引,会提高查询速度: create index 索引名 on 表名(列名); create index index_userid on tbl_detail(userid);如何找 ...
- Do Palapala (this)
Description 伟大的中国人民有宝箱容量为S(0<=S<=20000),有m个物品(0<m<=30,每个物品有一个体积(正整数).任取若干个装入箱内,使箱子的剩余空间为 ...
- Qt中OpenGL的初步使用
结果预览: 一.代码5个文件 //glwidget.h #ifndef GLWIDGET_H #define GLWIDGET_H #include <QGLWidget> class G ...
- 算法_php猴子选大王_约瑟夫问题
题目: n个猴子围坐一圈,从第一个猴子开始数,到第m个出列,求最后一个猴子的编号. 分析: 首先想到循环,然后队列,然后堆,所以用数组模拟一个循环的列表,下标为[0-(n-1)],下标+1整除m干掉元 ...
- 列表checkbox全选
$(document).ready(function(){ $(":checkbox:eq(0)").change(function(){ if ($(this).is(" ...
- python 爬虫时遇到问题及解决
源代码: #unicoding=utf-8import reimport urllib def gethtml(url): html=urllib.urlopen(url) page=html.rea ...
- centos6.5图形界面NetworkManager 配置ip文件位置
请教一个关于网络配置的问题,如图:该网络连接图形界面中 有2个配置,其中System eth0 有对应的配置文件/etc/sysconfig/network-scripts/ifcfg-eth0,但是 ...
- poj3006---素数筛法
#include <stdio.h> #include <stdlib.h> ];//以后都用宏定义 MAX int main()//如要将包括1000000在内的打表,数组就 ...
- denoising autoencoder
神经网络的挑战和关键技术: 1.神经网络结构决定(层,神经元,连接) 加入特定领域的知识(CNN 图片处理) 2.模型复杂度高 大的数据量: regularization: dro ...