HDU2685(gcd的定理)
来源:互联网 发布:编程用笔记本电脑推荐 编辑:程序博客网 时间:2024/06/05 04:25
马上区域赛网络赛了,整理了一些公式,本题是一个公式的模板题。
公式:
公式变形:
直接套公式做就好了
code:
#include<stdio.h>#include<string.h>#include<math.h>#include<algorithm>#include<iostream>#include<string>#include <set>//a&3==a%4using namespace std;#define ll long long#define mem(a) memset(a,0,sizeof(a))const double eps=1e-8;const int maxn=30010;//须填写const int inf=0x3f3f3f3f;int read() { //输入外挂 int res = 0; bool flag =false; char ch; if((ch = getchar()) == '-') flag = true; else if(ch >= '0' && ch <= '9') res = ch - '0'; while((ch = getchar()) >= '0' && ch <= '9') res = res * 10 + (ch - '0'); return flag ? -res : res;}int mod;int gcd(int x,int y){ if(y==0) return x; else return(gcd(y,x%y));}int quickpow(int a,int b){ int ans=1; while(b) { if(b&1) { ans=(ans*a)%mod; b--; } b=b>>1; a=(a*a)%mod; } ans=ans%mod; return ans;}int main(){ int kase; int a,m,n; kase=read(); while(kase--) { a=read(); m=read(); n=read(); mod=read(); int pow=gcd(m,n); int res=(quickpow(a,pow)+mod-1)%mod;//这里要处理一下,不然可能出现负数 // cout<<pow<<endl; cout<<res<<endl; } return 0;}//寇瑟茹酒
阅读全文
0 0
- HDU2685(gcd的定理)
- GCD(容斥定理)
- hdu 1695 GCD(容斥定理)
- HDU 1695 GCD(容斥定理)
- hdu2685(有点偏啊,不过可以看看数学证明)
- GCD SUM 强大的数论,容斥定理
- 斐波那契数和GCD的关系定理
- HDU 4497 GCD and LCM(唯一分解定理+排列组合)
- hdu 4497 GCD and LCM (唯一分解定理 + 计数)
- bzoj 1441: Min (gcd+裴蜀定理)
- [Codeforces338D]GCD Table(扩展中国剩余定理)
- codeforces 338D GCD Table (扩展中国剩余定理)
- bzoj 2299: [HAOI2011]向量 (gcd+裴蜀定理)
- HDU-1695 GCD(容斥定理+欧拉函数)
- GCD Again 唯一分解定理
- [乱搞]斐波那契数列与gcd之间一个有趣的定理
- 【Codeforces】338 D GCD Table 中国剩余定理(孙子定理)
- hdu 2841 Visible Trees&& hdu 1695 GCD(容斥定理+数论)
- 关于vs Code debug node.js
- 无名 2
- 火狐浏览器兼容
- 解决inline-block元素的 bug
- 视图
- HDU2685(gcd的定理)
- win8安装PCL1.8.1配置VS2017
- 将本地文档库提交到Github
- LintCode:M-单词切分
- JDBC中的四个最基本对象功能及其用法
- 23种设计模式-jvm-linux-nio-psb-集合-线程
- ZOJ3609 Modular Inverse (扩展欧几里得)
- c++基础之字符
- 第4课: Spark Streaming的Exactly-One的事务处理和不重复输出彻底掌握