HDU 2685 I won't tell you this is about number theory
来源:互联网 发布:差分演化算法及其应用 编辑:程序博客网 时间:2024/06/06 03:11
To think of a beautiful problem description is so hard for me that let’s just drop them off. :)
Given four integers a,m,n,k,and S = gcd(a^m-1,a^n-1)%k,calculate the S.
Input
The first line contain a t,then t cases followed.
Each case contain four integers a,m,n,k(1<=a,m,n,k<=10000).
Output
One line with a integer S.
eg:
intput
1
1 1 1 1
output
0
题意:S = gcd(a^m-1,a^n-1)%k,求s;
需要知道一个公式:
gcd(a^(m-1),a^(n-1)) = (a^gcd(m,n))-1
推广式:
若 gcd(a,b)=1
gcd(a^m-b^m,a^n-b^n) = a^gcd(m,n)-b^gcd(m,n)
代码:
#include<cstdio>#define ll long longll Gcd(ll x,ll y){ return y?Gcd(y,x%y):x;}int main(){ ll n,m,a,k,t; scanf("%lld",&t); while(t--) { scanf("%lld%lld%lld%lld",&a,&m,&n,&k); ll s=Gcd(m,n); ll Pow=1; for(int i=1;i<=s;i++) { Pow*=a; Pow%=k; } Pow%=k; ll ans=(Pow-1+k)%k; printf("%lld\n",ans); } return 0;}
阅读全文
0 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 数学结论
- HDU 2685 I won't tell you this is about number theory
- 【HDU2685】I won't tell you this is about number theory
- 数论基础定理及其应用(hdu 2685 I won't tell you this is about number theory, hdu 2582 f(n),hdu 1792 A New Chan)
- HDU 2685-I won't tell you this is about number theory(gcd(A^m-B^m,A^n-B^n)化简)
- 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!
- java的volatile图例
- 对知行合一的一点理解
- 面试相关知识和技巧
- c++对象导出到lua
- leetcode[Distribute Candies]//待整理多种解法
- HDU 2685 I won't tell you this is about number theory
- codeforces 841C Leha and Function
- 收藏(持续更新中)
- 算法竞赛入门经典java版程序CH3 UVa1368
- 安卓新版本升级,并自动安装apk
- 每天每周每月每年程序员该做的事情
- Leetcode--Longest Palindromic Substring(最长回文子序列)
- Execution failed for task ':app:mergeDebugResources'. > Error: java.util.concurrent.ExecutionExcepti
- Codeforces round#429 div2 C