题目大意:给你N和K,问有多少个数对满足gcd(N-A,N)*gcd(N-B,N)=N^K。
题解:由于 gcd(a, N) <= N,于是 K>2 都是无解,K=2 只有一个解 A=B=N,只要考虑K=1的情况就好了其实上式和这个是等价的gcd(A,N)*gcd(B,N)=N^K,我们枚举gcd(A,N)=g,那么gcd(B,N)=N/g。问题转化为统计满足 gcd(A, N)=g的A的个数。这个答案就是 ɸ(N/g),只要枚举 N 的 约数就可以了。答案是 Σɸ(N/g)*ɸ(g)(g|N)。
#include <cstdio>
typedef long long LL;
const int MOD=1000000007;
LL Eular(LL n){
LL ret=1;
for(LL i=2;i*i<=n;i++){
if(n%i==0){
n/=i,ret*=i-1;
while(n%i==0)n/=i,ret*=i;
}
}if(n>1)ret*=(n-1);
return ret;
}
int main(){
int n,k;
while(~scanf("%d%d",&n,&k)){
if(n==1||k==2){puts("1");continue;}
if(k>2){puts("0");continue;}
LL ans=0;
for(LL i=1;i*i<=n;i++)if(n%i==0){
LL t=Eular(i)*Eular(n/i)%MOD;
(ans+=t)%=MOD;
if(i*i!=n)(ans+=t)%=MOD;
}printf("%d\n",(int)ans);
}return 0;
}

HDU 4983 Goffi and GCD的更多相关文章

  1. hdu 4983 Goffi and GCD(数论)

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

  2. HDU 4983 Goffi and GCD(数论)

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

  3. hdu 4983 Goffi and GCD(欧拉函数)

    Problem Description Goffi is doing his math homework and he finds an equality on his text book: gcd( ...

  4. 【HDOJ】4983 Goffi and GCD

    题意说的非常清楚,即求满足gcd(n-a, n)*gcd(n-b, n) = n^k的(a, b)的不同对数.显然gcd(n-a, n)<=n, gcd(n-b, n)<=n.因此当n不为 ...

  5. HDU 4981 Goffi and Median(水)

    HDU 4981 Goffi and Median 思路:排序就能够得到中间数.然后总和和中间数*n比較一下就可以 代码: #include <cstdio> #include <c ...

  6. HDU 4982 Goffi and Squary Partition(推理)

    HDU 4982 Goffi and Squary Partition 思路:直接从全然平方数往下找,然后推断是否能构造出该全然平方数,假设能够就是yes,假设都不行就是no.注意构造时候的推断,因为 ...

  7. hdu 5869 区间不同GCD个数(树状数组)

    Different GCD Subarray Query Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K ( ...

  8. hdu 5656 CA Loves GCD(n个任选k个的最大公约数和)

    CA Loves GCD  Accepts: 64  Submissions: 535  Time Limit: 6000/3000 MS (Java/Others)  Memory Limit: 2 ...

  9. hdu 4983 欧拉函数

    http://acm.hdu.edu.cn/showproblem.php?pid=4983 求有多少对元组满足题目中的公式. 对于K=1的情况,等价于gcd(A, N) * gcd(B, N) = ...

随机推荐

  1. Android 拨号器的简单实现

    功能实现:一个EditView 一个拨打按钮,输入号码跳转到拨号界面 界面布局:activity_call.xml //线性垂直布局:一个EditView文本.一个Button按钮 1 <Lin ...

  2. codeforces 652E . Pursuit For Artifacts 强连通分量

    题目链接 题目大意: 给一个图, n个点m条边, 某些边上面有权值. 一条边只能走一次, 给两个点s, t. 问你, 从s到t能否经过有权值的边. 首先肯定要缩点, 然后看同一个连通分量里面的边, 是 ...

  3. 汇编写下strcpy

    #include <stdio.h> int main() { char *source = "hello world\n"; ] = {}; char *p = de ...

  4. HTML5学习笔记之Input类型

    Input类型——email email类型用于包含email地址的输入域,在输入地址时会自动验证email域的值 例:Email:<input type="email" n ...

  5. Delphi Socket Demo

    Delphi Socket Demo 转自  http://www.anqn.com/dev/delphi/2010-01-07/a09122531-1.shtml   自己对中间有点修改,下面是代码 ...

  6. poj1936---subsequence(判断子串)

    #include<stdlib.h> #include<stdio.h> int main() { ],t[]; char *p1,*p2; while(scanf(" ...

  7. C语言 linux环境基于socket的简易即时通信程序

    转载请注明出处:http://www.cnblogs.com/kevince/p/3891033.html      ——By Kevince 最近在看linux网络编程相关,现学现卖,就写了一个简易 ...

  8. 面向对象程序设计-C++_课时11new & delete

    Dynamic memory allocation new new int; new Stash; new int[10]; new返回这个对象的指针 delete delete p; delete[ ...

  9. SQLite for C#

    slqlite是个轻量级的数据库,是目前较为流行的小型数据库,适用于各个系统..NET自然也是支持的 1.添加2个引用System.Data.SQLite.Linq,System.Data.SQLit ...

  10. JS学习笔记(一)基本数据类型和对象类型

    js是一种弱类型的语言,所有的变量都用var进行声明,字符串用双引号或单引号括起来,常见基本数据类型为number,string,boolean等.如 var num = 123;或var num = ...