http://acm.hdu.edu.cn/showproblem.php?pid=4983

求有多少对元组满足题目中的公式。

对于K=1的情况,等价于gcd(A, N) * gcd(B,
N) = N,我们枚举 gcd(A, N) = g,那么gcd(B, N) = N / g。问题转化为统计满足 gcd(A, N) = g 的 A 的个数。这个答案就是 ɸ(N/g)

只要枚举 N 的 约数就可以了。答案是 Σɸ(N/g)*ɸ(g) g | N

暴力即可

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <string>
#include <queue>
#include <map>
#include <iostream>
#include <algorithm>
using namespace std;
#define RD(x) scanf("%d",&x)
#define RD2(x,y) scanf("%I64d%d",&x,&y)
#define RD3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define clr0(x) memset(x,0,sizeof(x))
typedef long long LL;
const int modo = 1e9 + 7;
int k; LL euler_phi(LL n) {
LL m = sqrt(n+0.5);
LL ret = n;
for (LL i = 2; i <= m; i++) {
if (n % i == 0) {
ret = ret / i * (i-1);
while (n%i==0)
n /= i;
if(n == 1)
break;
}
} if (n > 1)
ret = ret / n * (n - 1);
return ret;
}
LL n;
int main() {
// int _;RD(_);while(_--){
// ;
// }
while(~RD2(n,k)){
if(n == 1 || k == 2)
puts("1");
else if(k > 2)
puts("0");
else{
LL ans = 0;
LL m = sqrt(n + 0.5);
for(LL i = 1;i <= m;++i){
if(n % i == 0){
ans = (ans + euler_phi(i)*euler_phi(n/i)*2) % modo;
}
}
if(m*m == n){
ans = (ans + modo - euler_phi(m)*euler_phi(m)) % modo;
}
printf("%I64d\n",ans);
}
}
return 0;
}

hdu 4983 欧拉函数的更多相关文章

  1. hdu 6390 欧拉函数+容斥(莫比乌斯函数) GuGuFishtion

    http://acm.hdu.edu.cn/showproblem.php?pid=6390 题意:求一个式子 题解:看题解,写代码 第一行就看不出来,后面的sigma公式也不会化简.mobius也不 ...

  2. hdu 2654(欧拉函数)

    Become A Hero Time Limit: 15000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)To ...

  3. hdu 2824(欧拉函数)

    The Euler function Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Other ...

  4. hdu 1395(欧拉函数)

    2^x mod n = 1 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tot ...

  5. hdu 3307(欧拉函数+好题)

    Description has only two Sentences Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65536/327 ...

  6. 找新朋友 HDU - 1286 欧拉函数模板题

    题意: 求出来区间[1,n]内与n互质的数的数量 题解: 典型的欧拉函数应用,具体见这里:Relatives POJ - 2407 欧拉函数 代码: 1 #include<stdio.h> ...

  7. hdu 2824 欧拉函数 O(nlogn) 和O(n)

    裸题 O(nlogn): #include <cstdio> #include <iostream> #include <algorithm> using name ...

  8. hdu 4002 欧拉函数 2011大连赛区网络赛B

    题意:求1-n内最大的x/phi(x) 通式:φ(x)=x*(1-1/p1)*(1-1/p2)*(1-1/p3)*(1-1/p4)…..(1-1/pn),其中p1, p2……pn为x的所有质因数,x是 ...

  9. hdu 1787(欧拉函数)

    GCD Again Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total S ...

随机推荐

  1. js中常见的内置对象

    <!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...

  2. MySql的基本架构续

    [数据拆分后引入的问题] 数据水平拆分引入的问题主要是只能通过sharding key来读写操作,例如以userid为sharding key的切分例子,读userid的详细信息时,一定需要先知道us ...

  3. django创建工程,用命令

    django创建工程的命令 >>python C:\Python33\Lib\site-packages\django\bin\django-admin.py startproject p ...

  4. Eclipse中的SVN操作

    --------------------siwuxie095                                     Eclipse 中的 SVN 操作         (一)发布项目 ...

  5. 关于"undefined reference"错误

    这个错误换句话说: 链接的时候找不到实现的文件(谨记从这个入手!). 可能导致的原因有: 1. 没有链接库文件,包括静态库或动态库. 2. 链接文件的顺序问题,先后依赖问题,把被依赖的放后面. 3. ...

  6. 【校招面试 之 C/C++】第7题 C++构造函数不能是虚函数的原因

    1.虚拟函数调用只需要“部分的”信息,即只需要知道函数接口,而不需要对象的具体类型.但是构建一个对象,却必须知道具体的类型信息.如果你调用一个虚拟构造函数,编译器怎么知道你想构建是继承树上的哪种类型呢 ...

  7. Django的admin介绍

    我们看到我们创建一个默认的django的项目,他在project的urls有一个admin的url的路径 我们访问这个路径,他是一个登陆框,需要输入用户名和密码 我们就需要创建这个用户名和密码,如果你 ...

  8. swift - tableview 滚动到指定位置

    滚动一定要在  tableView.reloadData()之后进行 1. 默认  plain 模式 办法1. tableView.contentOffset.y = 0 办法2 tableView. ...

  9. [leetcode]636. Exclusive Time of Functions函数独占时间

    Given the running logs of n functions that are executed in a nonpreemptive single threaded CPU, find ...

  10. 如何在64位WIN7旗舰版下安装SQL2000

    1>找到安装包下面的“DEVELOPER”或“ENTERPRISE”等下的X86\SETUP下的“SETUPSQL.EXE”,在安装前右键单击这个文 件, 1.1 打开“兼容性”标签,兼容模式选 ...