【HDU2685】I won't tell you this is about number theory
来源:互联网 发布:java前端开发 编辑:程序博客网 时间:2024/06/08 18:13
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2685
题解:
这道题的题目背景是我见过最美妙最简洁最通俗易懂的题目背景
要知道一个公式
这里B=1
证明过程:
由乘法公式(x-y)(x^(k-1)+x^(k-2)y+…+y^(k-1)) = x^k-y^k,
可知a^(m,n)-b^(m,n) | a^m-b^m, a^(m,n)-b^(m,n) | a^n-b^n,
进而有a^(m,n)-b^(m,n) | (a^m-b^m,a^n-b^n).
只需再证明(a^m-b^m,a^n-b^n) | a^(m,n)-b^(m,n).
设c = (a^m-b^m,a^n-b^n), 则(c,b) = 1.
若不然, 设质数p | (c,b), 由p | b, p | c | a^m-b^m得p | a^m.
可得p | a, p | (a,b), 与(a,b) = 1矛盾, 故(c,b) = 1.
设d = (m,n), 由Bezout定理, 存在正整数u, v, 使um-vn = (m,n) = d.
由c | a^n-b^n, 有c | a^(vn)-b^(vn), 进而c | a^d·(a^(vn)-b^(vn)) = a^(um)-a^d·b^(vn).
而由c | a^m-b^m, 有c | a^(um)-b^(um).
相减得c | a^d·b^(vn)-b^(um) = (a^d-b^d)·b^(vn).
但(c,b) = 1, 于是c | a^d-b^d, 即(a^m-b^m,a^n-b^n) | a^(m,n)-b^(m,n).
#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#define LL long longusing namespace std;LL a,n,m,k;LL gcd(LL x,LL y){ return (!y)?x:gcd(y,x%y);}LL ksm(LL a,LL b,LL mod){ LL ans=1; while(b) { if(b&1) ans=(ans*a)%mod; a=(a*a)%mod; b>>=1; } return ans % mod;}int main(){ int t; cin>>t; while(t--) { scanf("%lld%lld%lld%lld",&a,&n,&m,&k); LL GCD=gcd(m,n); printf("%lld\n",(ksm(a,GCD,k)-1+k)%k); } return 0;}
- 【HDU2685】I won't tell you this is about number theory
- HDU 2685 I won't tell you this is about number theory (数论 公式 快速幂取模)
- HDU 2685 I won't tell you this is about number theory 数学结论
- HDU 2685 I won't tell you this is about number theory
- HDU 2685-I won't tell you this is about number theory(gcd(A^m-B^m,A^n-B^n)化简)
- 数论基础定理及其应用(hdu 2685 I won't tell you this is about number theory, hdu 2582 f(n),hdu 1792 A New Chan)
- I won't if you won't
- Why I Won't Hire You
- Why I Won’t Hire You
- Did I ever tell you about Ashton?
- Office Technology Ten Things Your IT Department Won't Tell You
- Tell you more about Zend_Form
- Three Things About Data Science You Won't Find In the Books
- I won't give up, I won't break down
- This is it——I just can't stop loving you
- 欺诈邮件:You've won a Microsoft X-Box (This is not spam)
- If I Could Tell You
- You should know this about T & F & Y!
- iOS手势(滑动)返回的实现(自定义返回按钮)
- Spring MVC学习笔记(一)
- POJ 2777 Count Color (线段树+状态压缩)
- ubuntu 16.04 安装php扩展
- swift3 激光推送的消息推送和接收
- 【HDU2685】I won't tell you this is about number theory
- oracle-用户锁、解锁
- Java常用的正则表达式与语法
- LightOJ
- more effective c++之Item M1:指针与引用的区别
- mysql存储过程游标嵌套示例
- 同时启动2个tomcat注意
- leetcode 268. Missing Number
- java微信公众号支付授权