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. SQL事务日志备份时的问题

    1.在进行事务日志备份的时候,如下图: 3041 消息的疑难解答时的考虑事项:不会只是一个数据库或所有数据库出现问题吗?是备份到本地存储区或远程存储吗?哪种类型的备份 (数据库备份. 日志备份和差异备 ...

  2. Typora快捷键的使用

    无序列表:输入-之后输入空格 有序列表:输入数字+“.”之后输入空格 任务列表:-[空格]空格 文字 标题:ctrl+数字 表格:ctrl+t 生成目录:[TOC]按回车 选中一整行:ctrl+l 选 ...

  3. springmvc DispatchServlet初始化九大加载策略(三)

    7. initRequestToViewNameTranslator 请求视图名 它主要与视图解析有关,如果对ViewResolvers.ModelAndView.View等没有多大印象,可以先看第8 ...

  4. Codeforces Beta Round #9 (Div. 2 Only)

    Codeforces Beta Round #9 (Div. 2 Only) http://codeforces.com/contest/9 A gcd水题 #include<bits/stdc ...

  5. 单词拆分 I · Word Break

    [抄题]: 给出一个字符串s和一个词典,判断字符串s是否可以被空格切分成一个或多个出现在字典中的单词. s = "lintcode" dict = ["lint" ...

  6. ROS Learning-008 beginner_Tutorials ROS话题

    ROS Indigo beginner_Tutorials-07 ROS话题 我使用的虚拟机软件:VMware Workstation 11 使用的Ubuntu系统:Ubuntu 14.04.4 LT ...

  7. Cannot find autoconf. Please check your autoconf installation and the $PHP_AUTOCONF environment variable. Then, rerun this scrip

    在运行phpize时出现的错误 > /data/php/bin/phpize Configuring for: PHP Api Version: 20131106 Zend Module Api ...

  8. 【转】HttpApplication的认识与加深理解

    原文:http://www.cnblogs.com/whtydn/archive/2009/10/16/1584584.html HttpApplication对象是经由HttpApplication ...

  9. Asia Stock Exchanges[z]

    Asia Stock Exchanges July 7, 2009 This article is to summarise the trading rules of some Asia stocke ...

  10. ObjC.instancetype

    1. instancetype http://nshipster.com/instancetype/ 2. Objc的扩展 http://clang.llvm.org/docs/LanguageExt ...