题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2685

题意:求gcd(a^m - 1, a^n - 1) mod k

思路:gcd(a^m - 1, a^n - 1) = a^gcd(m, n) - 1

code:

 #include <stdio.h>

 int gcd(int a, int b)
{
return !b ? a : gcd(b, a%b);
} int mod_pow(int a, int x, int mod)
{
int tmp = a;
int ret = ;
while(x) {
if (x & ) {
ret = ret * tmp % mod;
}
tmp = tmp * tmp % mod;
x >>= ;
} return ret;
} int main()
{
int t, a, m, n, k;
scanf("%d", &t);
while (t--) {
scanf("%d %d %d %d", &a, &m, &n, &k);
int d = gcd(m, n);
int ans = mod_pow(a, d, k);
printf("%d\n", (ans - + k) % k);
} return ;
}

HDU 2685 I won't tell you this is about number theory的更多相关文章

  1. hdu 2685 I won't tell you this is about number theory 数论

    题目链接 根据公式 \[ gcd(a^m-1, a^n-1) = a^{gcd(m, n)}-1 \] 就可以很容易的做出来了. #include <iostream> #include ...

  2. 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 ...

  3. hdu 2685(数论相关定理+欧几里德定理+快速取模)

    I won't tell you this is about number theory Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: ...

  4. HDU 1210 Eddy's 洗牌问题(foj1062) || FOJ1050 Number lengths水

    麻痹,感冒了. ------------------------------------------------感冒了的分割线------------------------------------- ...

  5. 2018HDU多校训练-3-Problem D. Euler Function

    链接:http://acm.hdu.edu.cn/showproblem.php?pid=6322 Problem Description In number theory, Euler's toti ...

  6. HDU 3341 Lost's revenge(AC自动机+DP)

    Lost's revenge Time Limit: 15000/5000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)T ...

  7. HDU 3336 Count the string(KMP的Next数组应用+DP)

    Count the string Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  8. HDU 5584 LCM Walk 数学

    LCM Walk Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=5584 ...

  9. HDU 5778 abs (枚举)

    abs 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5778 Description Given a number x, ask positive ...

随机推荐

  1. leetcode_question_130 Surrounded Regions

    Given a 2D board containing 'X' and 'O', capture all regions surrounded by 'X'. A region is captured ...

  2. 用HTML5、地理定位API和Web服务来开发移动应用

    HTML 5 是一项让人振奋的技术,这有着充分的理由.这将会是一次技术突破,因为它可以将桌面应用程序功能带入浏览器中.除了传统浏览器外,对于移动浏览器,其潜力甚至更大.不仅如此,最流行的移动浏览器甚至 ...

  3. document load 与document ready的区别

    页面加载完成有两种事件 1.load是当页面所有资源全部加载完成后(包括DOM文档树,css文件,js文件,图片资源等),执行一个函数 问题:如果图片资源较多,加载时间较长,onload后等待执行的函 ...

  4. css 元素居中方法

    目前知道有两种方法 方法一:主要适用于元素未设定高度的情况下. 直接上代码 html: <div class="nav-content"> <ul ng-clic ...

  5. 基于jQuery的前端如何做到无伤迁移

    首先,解释一下我个人对前端无伤迁移的理解,即移动端和PC端使用同一套代码,或者说原本在PC端运行得很完美的代码,只要修改少许,就可以在移动端完美运行. 当然,大部分的公司会专门为移动端设计了一套,同时 ...

  6. 手机访问电脑wampServer本地环境页面

    1.  电脑需要安装好wamp,我这里用的2.0版本,下载地址   http://pan.baidu.com/s/1jG31hbS   2. 电脑需要有个wifi,我用的360wifi   3. 启动 ...

  7. HTML5中的服务器‘推送’技术 -Server-Sent Events

    转帖:http://www.developersky.net/thread-63-1-1.html 一直以来,HTTP协议都是严格遵循Request-Response模型的.客户端发送一个Reques ...

  8. Noldbach problem

    Description Noldbach problem time limit per test: 2 seconds memory limit per test: 64 megabytes inpu ...

  9. jQuery验证控件(转载)

    转自:http://www.cnblogs.com/hejunrex/archive/2011/11/17/2252193.html 官网地址:http://bassistance.de/jquery ...

  10. mininet 中图形化界面的安装

    just run a GUI in VM console window First, log in to the VM in its console window (i.e. type directl ...