题意说的非常清楚,即求满足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. 设置IIS7文件上传的最大大小 maxAllowedContentLength,maxRequestLength

    当上传一个超过30M的文件时,服务器会重定向至404.13页面,报错如下: HTTP Error 404.13 - Not Found The request filtering module is ...

  2. [Angular 2] ng-model and ng-for with Select and Option elements

    You can use Select and Option elements in combination with ng-for and ng-model to create mini-forms ...

  3. mysql源码分析

    http://blog.csdn.net/u012935160/article/category/2697485

  4. When does layoutSubviews get called?

    转自:http://blog.logichigh.com/2011/03/16/when-does-layoutsubviews-get-called/ It’s important to optim ...

  5. 从零开始学习jquery (二)

    前面我们了解到了如何获取使用jquery,下面我们主要看看jquery的一些语法.基本的语法 $(selector).action(). 美元符号定义 jQuery 选择符(selector)&quo ...

  6. Android Studio下打jar包

    在我们使用Eclipse时,我们常常使用的第三方类库文件大多都是jar包形式,用起来很方便.但是jar包只能打包class文件,对于Android UI类库而言,我们常常需要打包资源文件,对于界面不多 ...

  7. C#-高血压生活习惯数据模拟

    using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace test ...

  8. JavaScript--时间显示小插件

    JS调用系统时间,显示在当前页面上,利用DOM操作节点来实现动态刷新 <!DOCTYPE html> <html> <head> <meta charset= ...

  9. 得于吾师傅的js知识 js类,单写模板,和私有保护的方法

    js的类的写法: 1,写法一:function内部包含this.function()如代码: var origin_class = function(name) { var lover = ''; t ...

  10. ICOMOON!强悍的WEB字体图标制造器/Web字体使用实例

    IcoMoon!一个可以通过个性化设置来创建自定义图标(字体)的生成器!也可以将SVG图片,转换成web字体 IcoMoon是一项免费的服务,通过使用不同设置使我们能够创建自定义的ICON图或ICON ...