Problem Description

Goffi is doing his math homework and he finds an equality on his text book: gcd(n−a,n)×gcd(n−b,n)=nk.

Goffi wants to know the number of (a,b) satisfy the equality, if n and k are given and 1≤a,b≤n.

Note: gcd(a,b) means greatest common divisor of a and b.

 
Input
Input contains multiple test cases (less than 100). For each test case, there's one line containing two integers n and k (1≤n,k≤109).
 
Output
For each test case, output a single integer indicating the number of (a,b) modulo 109+7.
 
Sample Input
 
 
Sample Output

Hint

For the first case, (2, 1) and (1, 2) satisfy the equality.

 
Source
 发现自己欧拉函数都给忘记了,所有赶紧补题。。。
1、k!=1时情况很简单,记住将if(k==2 || n==1)这个特判放在if(k>2)的前面,因为这个WA了很久,各种原因自己思考。
2、下面讨论k=1时情况。x=gcd(n-a,n),则n/x=gcd(n-b,n),因为n-a可以取到0...n-1也就是1....n,所以完全可以去掉n-这个限制条件,即gcd(a,n)=x、gcd(b,n)=n/x时个数,因为a<=n,所以gcd(a,n)的个数=u[n/x],u是欧拉函数。所以原式等于sigma(u[n/x]*u[x])其中x是n的约数。
 #include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
#define MOD 1000000007
#define ll long long
ll eular(ll n)
{
ll res=;
for(ll i=;i*i<=n;i++)
{
if(n%i==)
{
n/=i,res*=i-;
while(n%i==)
{
n/=i;
res*=i;
}
}
}
if(n>) res*=n-;
return res;
}
ll n,k;
int main()
{
while(scanf("%I64d%I64d",&n,&k)==)
{
if(k== || n==)
{
printf("1\n");
continue;
}
if(k>)
{
printf("0\n");
continue;
} ll ans=;
for(ll i=;i*i<=n;i++)
{
if(n%i==)
{
if(i*i!=n)
ans=(ans+eular(n/i)*eular(i)*)%MOD;
else
ans=(ans+eular(n/i)*eular(i))%MOD;
}
}
printf("%I64d\n",ans); }
return ;
}

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 1695 GCD 欧拉函数+容斥定理 || 莫比乌斯反演

    GCD Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...

  4. HDU 2588 GCD (欧拉函数)

    GCD Time Limit: 1000MS   Memory Limit: 32768KB   64bit IO Format: %I64d & %I64u Submit Status De ...

  5. HDU 1695 GCD 欧拉函数+容斥定理

    输入a b c d k求有多少对x y 使得x在a-b区间 y在c-d区间 gcd(x, y) = k 此外a和c一定是1 由于gcd(x, y) == k 将b和d都除以k 题目转化为1到b/k 和 ...

  6. HDU 1695 GCD (欧拉函数,容斥原理)

    GCD Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submis ...

  7. hdu 1695 GCD (欧拉函数+容斥原理)

    GCD Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...

  8. HDU 4483 Lattice triangle(欧拉函数)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4483 题意:给出一个(n+1)*(n+1)的格子.在这个格子中存在多少个三角形? 思路:反着想,所有情 ...

  9. BZOJ 2818: Gcd [欧拉函数 质数 线性筛]【学习笔记】

    2818: Gcd Time Limit: 10 Sec  Memory Limit: 256 MBSubmit: 4436  Solved: 1957[Submit][Status][Discuss ...

随机推荐

  1. 对list集合去重操作

    import java.util.ArrayList; import java.util.List; //删除集合中重复的数据 public class RemoteTheSameDataInList ...

  2. [Angular 2] Async Http

    Async Pipe: The Asynce pipe receive a Promise or Observable as  input and subscribes to the input, e ...

  3. 大到可以小说的Y组合子(一)

    问:上回乱扯淡了一通,这回该讲正题了吧. 答:OK. 先来列举一些我参考过,并从中受到启发的文章. (1.)老赵的一篇文章:使用Lambda表达式编写递归函数 (2.)装配脑袋的两篇文章:VS2008 ...

  4. RPM包查询

    一.查询包是否安装 [root@localhost Packages]# rpm -q httpd            ---> 查询已安装的包(命令包名) #选项: #    -q    查 ...

  5. CentOS6.X 系统安装图文教程,超详细

    http://www.myhack58.com/Article/sort099/sort0102/2011/32363_7.htm

  6. Linux命令 rpm

    rpm -q samba                          --查询程序是否安装rpm -qa | grep httpd  --[搜索指定rpm包是否安装]  --all搜索*http ...

  7. HTML基础总结<头部>

    重点摘录:HTML head 元素 标签 描述 <head> 定义了文档的信息 <title> 定义了文档的标题 <base> 定义了页面链接标签的默认链接地址 & ...

  8. css如何实现背景透明,文字不透明?

    之前做了个半透明弹层,但设置背景半透明时,子元素包含的字体及其它元素也都变成了半透明.对opacity这个属性认识的不透彻,在这里做一些总结,方便以后使用.   背景透明,文字不透明的解决方法:   ...

  9. 转载——SQL Server中Rowcount与@@Rowcount的用法

    转载自:http://www.lmwlove.com/ac/ID943 rowcount的用法: rowcount的作用就是用来限定后面的sql在返回指定的行数之后便停止处理,比如下面的示例, set ...

  10. SqlServer跨域查询

    SELECT * FROM OPENDATASOURCE('SQLOLEDB','Data Source=192.168.1.14;User ID=sa;Password=sql.com').eBui ...