题意说的非常清楚,即求满足gcd(n-a, n)*gcd(n-b, n) = n^k的(a, b)的不同对数。显然gcd(n-a, n)<=n, gcd(n-b, n)<=n。因此当n不为1时,当k>2时,不存在满足条件的(a,b)。而当k=2时,仅存在(n, n)满足条件。因此仅剩n=1以及k=1需要单独讨论:
当n = 1时,无论k为何值,均有且仅有(1,1)满足条件,此时结果为1;
当k = 1时,即gcd(n-a, n)*gcd(n-b, n) = n,则令gcd(n-a, n) = i,则gcd(n-b, n) = n/i。也即求(n-a)/i与n/i互素且(n-b)/(n/i)与n/(n/i)互素的(a, b)的对数和。

 #include <cstdio>
#include <cmath> const int MOD = (1e9+); __int64 getNotDiv(int x) {
int i, r = x;
__int64 ret = x; for (i=; i*i<=r; ++i) {
if (x%i == ) {
ret -= ret/i;
while (x%i == )
x /= i;
}
}
if (x > )
ret -= ret/x;
return ret;
} int main() {
int n, k;
int i, j;
__int64 ans, tmp; while (scanf("%d %d", &n, &k) != EOF) {
if (n== || k==)
printf("1\n");
else if (k==) {
ans = ;
for (i=; i*i<=n; ++i) {
if (n%i == ) {
j = n/i;
tmp = getNotDiv(i)*getNotDiv(j)%MOD;
if (j == i) {
ans += tmp;
} else {
ans += tmp<<;
}
ans %= MOD;
}
}
printf("%I64d\n", ans%MOD);
} else {
printf("0\n");
}
} return ;
}

【HDOJ】4983 Goffi and GCD的更多相关文章

  1. 【HDOJ】4982 Goffi and Squary Partition

    题意就是整数划分,选出和为n的K个整数,其中K-1个数的和为完全平方数S.选择整数时需要从1,2,3..连续选择,当选择整数与n-S相等时,需要跳过n-S,即选择n-S+1.如此选择K-2个数,从而可 ...

  2. hdu 4983 Goffi and GCD(数论)

    题目链接:hdu 4983 Goffi and GCD 题目大意:求有多少对元组满足题目中的公式. 解题思路: n = 1或者k=2时:答案为1 k > 2时:答案为0(n≠1) k = 1时: ...

  3. HDU 4983 Goffi and GCD(数论)

    HDU 4983 Goffi and GCD 思路:数论题.假设k为2和n为1.那么仅仅可能1种.其它的k > 2就是0种,那么事实上仅仅要考虑k = 1的情况了.k = 1的时候,枚举n的因子 ...

  4. 【BZOJ】2820: YY的GCD

    [题意]给定N, M,求1<=x<=N, 1<=y<=M且gcd(x, y)为质数的(x, y)有多少对.T<=10^4,N,M<=10^7. [算法]数论(莫比乌 ...

  5. 【51NOD-0】1011 最大公约数GCD

    [算法]欧几里德算法 #include<cstdio> int gcd(int a,int b) {?a:gcd(b,a%b);} int main() { int a,b; scanf( ...

  6. 【数学】codeforces C. Maximal GCD

    http://codeforces.com/contest/803/problem/C [题意] 给定两个数n,k(1 ≤ n, k ≤ 10^10) 要你输出k个数,满足以下条件: ①这k个数之和等 ...

  7. 【HDOJ】3071 Gcd & Lcm game

    刚开始看这个题目,觉得没法做.关键点是数据小于100.因此,可以枚举所有小于100的素因子进行位压缩.gcd就是求最小值,lcm就是求最大值.c++有时候超时,g++800ms.线段树可解. /* 3 ...

  8. 【HDOJ】1695 GCD

    莫比乌斯反演简单题目. /* 1695 */ #include <iostream> #include <string> #include <map> #inclu ...

  9. 【HDOJ】4729 An Easy Problem for Elfness

    其实是求树上的路径间的数据第K大的题目.果断主席树 + LCA.初始流量是这条路径上的最小值.若a<=b,显然直接为s->t建立pipe可以使流量最优:否则,对[0, 10**4]二分得到 ...

随机推荐

  1. Android Activity启动模式

    <activity android:name=".MainActivity" android:launchMode="singleTask"> &l ...

  2. rpc远程过程协议调用

    在linux 5.X以及下的版本你可以通过service portmap status命令查看rpc是否启动.如果提示running,表示正在运行:如果提示stop就是关闭了.如果没有安装,则通过安装 ...

  3. RT: np - new sbt project generation made simple(r)

    np - new sbt project generation made simple(r) As pointed out in the comments by @0__ below, there's ...

  4. 尚未解决的intellij问题:补充措施

    2016-12-06 遇到问题 D:\software\apache-tomcat-7.0.57\bin\catalina.bat run [2016-12-06 09:54:52,342] Arti ...

  5. call()与apply()区别

    一.方法的定义 call方法: 语法:call(thisObj,Object)定义:调用一个对象的一个方法,以另一个对象替换当前对象.说明:call 方法可以用来代替另一个对象调用一个方法.call ...

  6. asp.net中过滤器的两种写法

    1.写在一个单独的类库中在web.config中进行配置 <httpModules> <add name="" type="类的全名称,程序集的名称&q ...

  7. dedecms 使noflag参数及其过滤多个属性的修改方法

    noflag='h' 是代表不包含头条属性的意思,其中flag就是属性, 自定义属性值:头条[h]推荐[c]图片[p]幻灯[f]滚动[s]跳转[j]图文[a]加粗[b]. noflag过滤多个属性的修 ...

  8. 苹果新政,禁止开发者在App中加入检查更新功能

    今天妥妥的被拒了,苹果更新了新政策,不能在应用中出现检测更新的功能.AppStore会自动提醒用户更新. 去掉更新按钮,之后再尝试下看能通过不能

  9. [转]Python中的with…as…

    先说明一个常见问题,文件打开: 1 2 3 4 5 6 7 try:     f = open('xxx')     do something except:     do something fin ...

  10. html5--canvas学习笔记

    1. 添加<canvas>元素 right: <canvas id="myCanvas" width="300" height="3 ...