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 ...
随机推荐
- Android学习之Notification
Notification可以在手机的状态栏发出一则通知,它需要用NotificationManager来管理,实现Notification其实很简单. 1.通过getsystemservice方法获得 ...
- KZ--NSString、NSMutableString
//NSString初始化的几种方法(3种方法) //1. NSString *str2 = [[NSString alloc] init]; ...
- 一个利用Dataflow实现的Actor
最近进行并发数据处理,学习到了 Actor模型,其中最简单的实现方式是一位大牛利用Dataflow实现的. 大牛的方案:http://www.jayway.com/2013/11/15/an-acto ...
- blog开篇
本来是写java学习开篇的,现在就把它改为博客开篇吧. 其实一直都想着记录一下自己学习的过程,或者说是借口,一直在忙,也从重庆辗转到广州,又从广州辗转到天津了,又一个新阶段开始了,猴年马月都到了,哈哈 ...
- C++ 动态分配类对象
1.概念 在C++中,类的对象建立分为两种,一种是静态建立,如A a:另一种是动态建立,如A* ptr=new A:这两种方式是有区别的. 静态建立一个类对象,是由编译器为对象在栈空间中分配内存,是通 ...
- Kurskal算法(克鲁斯卡尔算法)
特点:适用于稀疏图,边比较少的图.如果顶点较少,且为稠密图,则用Prim算法.跟Prim算法的用途相同.时间复杂度为O(e*loge),其中e为边数. 代码: #include <stdio.h ...
- python---连接MySQL第三页
用python语言从MySQL中查询数据 #!conding:utf-8 from mysql.connector import errorcode import mysql.connector cn ...
- JNDI(转载)
转自:http://javacrazyer.iteye.com/blog/759485 原理: 在DataSource中事先建立多个数据库连接,保存在数据库连接池中.当程序访问数据库时 ...
- 取PE文件的引入表和导出表
直接上代码(这里列出C++和Delphi的代码),Delphi代码中包含导入及导出文件和函数列表,PE结构可参阅资料,很多很详细,需要注意的是,本例中是映射到内存,不是通过PE装载器装入的,所以对于节 ...
- POJ 1182 食物链(并查集拆点)
[题目链接] http://poj.org/problem?id=1182 [题目大意] 草原上有三种物种,分别为A,B,C A吃B,B吃C,C吃A. 1 x y表示x和y是同类,2 x y表示x吃y ...