欧拉函数之HDU4983 Goffi and GCD
来源:互联网 发布:浏览器ip代理软件 编辑:程序博客网 时间:2024/06/08 01:56
首先gcd(n,x)< n,所以k>2是无解的。
当k=2,只有一组解(ps:gcd(n,0)=n)
只需求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的约数。(注意,n/x==x的情况)
ps:我认为这道题的精髓就在a<n,gcd(a,n)=x的个数=u[n/x]! 这一点理解了,那么hdu2588也就会写了~
#include <stdio.h>#include <ctype.h>#include <string.h>#include <stdlib.h>#include <limits.h>#include <math.h>#include <algorithm>#include <stack>#include <queue>#include <vector>#include <map>#include <set>#include <string>#include <sstream>using namespace std;#define lson l,m,rt<<1#define rson m+1,r,rt<<1|1typedef long long LL;const double pi=4.0*atan(1.0);const int MAXN=105;const int INF=1<<30;const LL M=1000000007;LL euler(LL n){ LL ans=n; for(int i=2;(LL)i*i<=n;i++) if(n%i==0) { ans=ans/i*(i-1); while(n%i==0) n/=i; } if(n>1) ans=ans/n*(n-1); return ans;}int main(){ LL n,k; while(scanf("%I64d%I64d",&n,&k)!=EOF) { if(n==1||k==2) { printf("1\n"); continue; } if(k>2) { printf("0\n"); continue; } LL ans=0; for(LL i=1;i*i<=n;i++) { if(n%i==0) { LL t=n/i; if(t==i) ans=(ans+euler(t)%M*euler(i)%M)%M; else ans=(ans+euler(t)%M*euler(i)%M*2%M)%M; } } printf("%I64d\n",ans); } return 0;}
0 0
- 欧拉函数之HDU4983 Goffi and GCD
- HDU4983 Goffi and GCD (欧拉函数求解gcd个数)
- HDU4983 Goffi and GCD
- hdu 4983 Goffi and GCD(欧拉函数)
- 【欧拉函数】 HDOJ 4983 Goffi and GCD
- [欧拉函数] hdu 4983 Goffi and GCD
- HDU 4983 Goffi and GCD(数列、欧拉函数)
- HDU-4983-Goffi and GCD【数论】【欧拉函数】
- bestcode#6—1003 HDU 4983 Goffi and GCD 【欧拉函数】
- HDOJ 题目4983 Goffi and GCD(数学,欧拉函数)
- hdu4983 / 枚举约数+欧拉函数
- BestCoder Round #6(1003)hdu4983(欧拉函数)
- HDOJ 4983 Goffi and GCD
- hdu 4893 Goffi and GCD
- hdu 4983 Goffi and GCD
- hdoj4893Goffi and GCD【欧拉函数】
- 欧拉函数之HDU2588 GCD
- HDU 4983 Goffi and GCD(数论)
- 讲座:与迷茫相伴的IT成长路
- ibatis 条件查询
- 乱码转换
- mac: macVim 安装颜色主题
- ListView 嵌套listView 怎么实现,及关于焦点问题的解决。
- 欧拉函数之HDU4983 Goffi and GCD
- Redis windons安装
- UML 继承 实现 依赖 关联
- Mac 下搭建xampp+elgg
- easyui 重复提交url
- 我的Java成长之路001
- 位运算知识点 (& ^ | )
- :nth-child(n)与:nth-of-type(n)的区别
- javaEE__jsp加强