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. JavaScript中的面向对象的讨论(转)

    前言 今天,WEB2.0时代的到来,给了JavaScript又一次大展身手的机会.Web2.0借助JavaScript技术,使得客户端的Web体验更加丰富多彩,同时JavaScript面对的问题域也变 ...

  2. ExtJS4.2学习(11)——高级组件之Grid

    大纲: 1.首先,搭建起来一个最基础的Grid组件: 2.其次,利用前边MVC架构将代码重构: 3.再者,介绍下Grid的一些特性. 一.搭建基础的Grid组件 在文章的开始,我们首先简单的搭建一个G ...

  3. FZU 1686 神龙的难题(DLX反复覆盖)

    FZU 1686 神龙的难题 pid=1686" target="_blank" style="">题目链接 题意:中文题 思路:每个1看成列, ...

  4. Java基础知识强化52:经典排序之冒泡排序(BubbleSort)

    1. 冒泡排序的原理图: 2. 冒泡排序代码实现: package cn.itcast_01; /* * 数组排序之冒泡排序: * 相邻元素两两比较,大的往后放,第一次完毕,最大值出现在了最大索引处 ...

  5. LSI SAS 3008配置操作

    配置 LSI SAS 3008 介绍LSISAS3008的配置操作. 4.1 登录CU界面 介绍登录LSISAS3008的CU配置界面的方法. 4.2 创建RAID 介绍在LSISAS3008扣卡上创 ...

  6. USB HID Report Descriptor 报告描述符详解

    Report descriptors are composed of pieces of information. Each piece of information is called an Ite ...

  7. css中表格的table-layout属性特殊用法

    table-layout: 属性1:auto,使用它,表格的大小由单元格里的内用决定,即td的宽高由内容的多少而变化. 属性2:fixed,如果内容是中文的话td的宽高固定,宽高有内容决定,没有限制. ...

  8. 使Asp.net WebApi支持JSONP和Cors跨域访问

    1.服务端处理 同源策略(Same Origin Policy)的存在导致了“源”自A的脚本只能操作“同源”页面的DOM,“跨源”操作来源于B的页面将会被拒绝.同源策略以及跨域资源共享在大部分情况下针 ...

  9. Swift - guard关键字(守护)

    guard语句和if语句有点类似,都是根据其关键字之后的表达式的布尔值决定下一步执行什么.但与if语句不同的是,guard语句只会有一个代码块,不像if语句可以if else多个代码块. 那么guar ...

  10. C#多态联系之虚方法

    class Class1 { static void Main(string[] args) { YuanGong yg = new YuanGong(); JingLi jl = new JingL ...