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. linux 批量删除文件名中有换行符

    ls -i | grep ^M | awk '{print $1}' | xargs -t -I [] find . -inum [] -exec rm -if {} \; 注意^M 是ctrl+v ...

  2. Path-O-LOGIC Keynote

    [Path-O-LOGIC Keynote] 1. OnSpawned()OnSpawned(SpawnPool pool) 2. OnDespawned()OnDespawned(SpawnPool ...

  3. android笔记 : Content provider内容提供器

    内容提供器(Content Provider)主要用于在不同的应用程序之间实现数据共享的功能. 内容提供器的用法一般有两种,一种是使用现有的内容提供器来读取和操作相应程序中的数据,另一种是创建自己的内 ...

  4. form表单的默认提交行为

    一 如果<form></form>表单中只有一个<input type="text"/>,则使文本框获取焦点,并单击回车,form会自动提交. ...

  5. mysql5.5以上开启慢查询

    在my.ini配置文件中添加: [mysqld] #开启慢查询 slow_query_log = on #慢查询时间 long_query_time = 0.5 #记录没有使用索引的查询 log_qu ...

  6. MVC扩展HtmlHelper,加入RadioButtonList、CheckBoxList、DropdownList

    代码: using System; using System.Collections.Generic; using System.Linq; using System.Linq.Expressions ...

  7. Java WebService 知识点汇总

    java webservice 获取传入IP axis.jar    servlet.jar MessageContext mMsgContext = MessageContext.getCurren ...

  8. [转]微信公众平台(测试接口)开发前的准备工作(转载自walkingmanc的专栏)

    本文转自:http://blog.csdn.net/jiangweicpu/article/details/21228949 http://blog.csdn.net/walkingmanc/arti ...

  9. 【原型实战】分分钟搞定Unsplash网站原型设计

    网站原型设计是我们在设计网页过程中必不可少的一步,激烈的市场竞争让我们不得不对产品进行快速迭代,如何高速有效的进行原型设计成为了设计师头疼的问题.本文将以unsplash网站为实例,教大家快速搞定we ...

  10. oracle常用函数速记

    1.截断中文字符串 CREATE OR REPLACE function cn_cutstr(v_str varchar2,v_len number) return varchar2 IS v_i n ...