hdu 2685(数论相关定理+欧几里德定理+快速取模)
I won't tell you this is about number theory
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 458 Accepted Submission(s): 142
Given four integers a,m,n,k,and S = gcd(a^m-1,a^n-1)%k,calculate the S.
Each case contain four integers a,m,n,k(1<=a,m,n,k<=10000).
1 1 1 1
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
using namespace std;
typedef long long LL;
LL pow_mod(LL a,LL n,LL mod){
LL ans = ;
while(n){
if(n&) ans = ans*a%mod;
a=a*a%mod;
n=n>>;
}
return ans;
}
LL gcd(LL a,LL b){
return b==?a:gcd(b,a%b);
}
int main()
{
int tcase;
scanf("%d",&tcase);
while(tcase--){
LL a,m,n,k;
scanf("%lld%lld%lld%lld",&a,&m,&n,&k);
LL t = gcd(m,n);
LL ans = (pow_mod(a,t,k)-+k)%k;
printf("%lld\n",ans);
}
return ;
}
hdu 2685(数论相关定理+欧几里德定理+快速取模)的更多相关文章
- Educational Codeforces Round 80 C. Two Arrays(组合数快速取模)
You are given two integers nn and mm . Calculate the number of pairs of arrays (a,b)(a,b) such that: ...
- 组合数学中的常见定理&组合数的计算&取模
组合数的性质: C(n,m)=C(n,n-m); C(n,m)=n!/(m!(n-m)!); 组合数的递推公式: C(n,m)= C(n-1,m-1)+C(n-1,m); 组合数一般数值较大,题目会 ...
- lucas定理解决大组合数取模
LL MyPow(LL a, LL b) { LL ret = ; while (b) { ) ret = ret * a % MOD; a = a * a % MOD; b >>= ; ...
- 位运算之——按位与(&)操作——(快速取模算法)
学习redis 字典结构,hash找槽位 求槽位的索引值时,用到了 hash值 & sizemask操作, 其后的scan操作涉及扫描顺序逻辑,对同模的槽位 按一定规则扫描! 其中涉及位运算 ...
- 【Java基础】14、位运算之——按位与(&)操作——(快速取模算法)
学习redis 字典结构,hash找槽位 求槽位的索引值时,用到了 hash值 & sizemask操作, 其后的scan操作涉及扫描顺序逻辑,对同模的槽位 按一定规则扫描! 其中涉及位运算 ...
- hdu 2582(数论相关定理+素数筛选+整数分解)
f(n) Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submis ...
- ACM-ICPC 2018 焦作赛区网络预赛G Give Candies(隔板定理 + 小费马定理 + 大数取模,组合数求和)题解
题意:给你n个东西,叫你把n分成任意段,这样的分法有几种(例如3:1 1 1,1 2,2 1,3 :所以3共有4种),n最多有1e5位,答案取模p = 1e9+7 思路:就是往n个东西中间插任意个板子 ...
- 【HDU 5832】A water problem(大数取模)
1千万长度的数对73和137取模.(两个数有点像,不要写错了) 效率要高的话,每15位取一次模,因为取模后可能有3位,因此用ll就最多15位取一次. 一位一位取模也可以,但是比较慢,取模运算是个耗时的 ...
- HDU——1395 2^x mod n = 1(取模运算法则)
2^x mod n = 1 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) To ...
随机推荐
- 使用Xshell对虚拟机上的Ubuntu系统进行远程连接
需要在Linux上安装openssh-server 1.在Ubuntu系统的终端下输入命令:sudo apt install openssh-server 2.在Xshell中输入指定连接的主机IP, ...
- 826. Most Profit Assigning Work
https://leetcode.com/problems/most-profit-assigning-work/description/ class Solution { public: int m ...
- A1027 Colors in Mars (20)(20 分)
A1027 Colors in Mars (20)(20 分) People in Mars represent the colors in their computers in a similar ...
- DFS:POJ1190-生日蛋糕(基础搜索)
生日蛋糕 Time Limit: 1000MS Memory Limit: 10000K 描述 7月17日是Mr.W的生日,ACM-THU为此要制作一个体积为Nπ的M层生日蛋糕,每层都是一个圆柱体. ...
- Android四大组件之服务
创建一个服务,并与活动绑定 作为安卓四大组件之一的服务,毫无例外也要在manifast中进行注册 新建服务类继承于Service,并覆盖onBind( )方法,用于与活动绑定 public class ...
- Ecplise实战常用操作快捷键(更新至2018年10月8日 13:46:40)
ctrl+鼠标左键 进入/查看这个类或者方法, ctrl + t 快速类型层次结构(出现部分方法) ctrl + o 快速大 ...
- 理解机器为什么可以学习(一)---Feasibility of learning
主要讲解内容来自机器学习基石课程.主要就是基于Hoeffding不等式来从理论上描述使用训练误差Ein代替期望误差Eout的合理性. PAC : probably approximately corr ...
- MongoDB01——安装MangoDB
一.MongoDB的下载 到MongoDB的官网——https://www.mongodb.com/download-center/community,选择要下载的版本,点击Download 二.安装 ...
- 一些echarts的基本图形
先拿一个图形渲染过程举例 引用处 <bar ref="ARPUChart" v-if="ARPUChart" style="width:500p ...
- 【bzoj4281】[ONTAK2015]Związek Harcerstwa Bajtockiego 树上倍增+LCA
题目描述 给定一棵有n个点的无根树,相邻的点之间的距离为1,一开始你位于m点.之后你将依次收到k个指令,每个指令包含两个整数d和t,你需要沿着最短路在t步之内(包含t步)走到d点,如果不能走到,则停在 ...