hdu 4983 欧拉函数
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 欧拉函数的更多相关文章
- hdu 6390 欧拉函数+容斥(莫比乌斯函数) GuGuFishtion
http://acm.hdu.edu.cn/showproblem.php?pid=6390 题意:求一个式子 题解:看题解,写代码 第一行就看不出来,后面的sigma公式也不会化简.mobius也不 ...
- hdu 2654(欧拉函数)
Become A Hero Time Limit: 15000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)To ...
- hdu 2824(欧拉函数)
The Euler function Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Other ...
- hdu 1395(欧拉函数)
2^x mod n = 1 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tot ...
- hdu 3307(欧拉函数+好题)
Description has only two Sentences Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65536/327 ...
- 找新朋友 HDU - 1286 欧拉函数模板题
题意: 求出来区间[1,n]内与n互质的数的数量 题解: 典型的欧拉函数应用,具体见这里:Relatives POJ - 2407 欧拉函数 代码: 1 #include<stdio.h> ...
- hdu 2824 欧拉函数 O(nlogn) 和O(n)
裸题 O(nlogn): #include <cstdio> #include <iostream> #include <algorithm> using name ...
- 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是 ...
- hdu 1787(欧拉函数)
GCD Again Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total S ...
随机推荐
- scikit Flow ,tensor flow 做ml模型
[https://github.com/ilblackdragon/tf_examples/blob/master/titanic.py] [keras 高层tensorflow] https://k ...
- do{}while() ;异常语句
//while (true) //只要括号里面是true(正确的如:(1==1)),就会无限循环 //{ //} //do{}while() //不管while满足与否,首先先做一遍 //然后去看wh ...
- Centos7 創建快捷方式
usr/share/applications 創建文件 Gogland.desktop [Desktop Entry]Version=1Type=ApplicationName=GoglandGene ...
- Ansible playbooks
Playbook是Ansible的配置,部署和编排语言. 他们可以描述您希望远程系统执行的策略,或一般IT流程中的一组步骤. 如果Ansible modules是您workshop的工具,则playb ...
- win10关闭后台应用程序进程的方法
一)win10系统后台应用有两大特点: 1.win10系统有许多系统自带应用软件,在系统任务栏中看不到任何自带的应用程序运行 2.但通过任务管理器的进程中,可直观的看到许多非系统进程正在运行. 二)后 ...
- MAVEN 引入外部JAR 包
MAVEN引入AXIS依赖的JAR包 在POM.XML中加入即可 <!-- axis 1.4 jar start --> <dependency> <groupId> ...
- Golang 获取MD5的方法
import ( "crypto/md5" "encoding/hex" ) //生成32位md5字串 func Md5(s string) string { ...
- HashCode的理解
一.hashcode是什么 要理解hashcode首先要理解hash表这个概念 1. 哈希表 hash表也称散列表(Hash table),是根据关键码值(Key value)而直接进行访问的数据结构 ...
- 第七章 二叉搜索树 (d2)AVL树:插入
- thrust
thrust - Bing dictionary US[θrʌst]UK[θrʌst] v.刺:塞:冲:挤 n.刺:插:重点:猛推 网络推力:插入:戳 变形Plural Form:thrusts:Pr ...