hdu 4983 Goffi and GCD
来源:互联网 发布:基于模型的推荐算法 编辑:程序博客网 时间:2024/05/12 05:41
参考博客:http://blog.csdn.net/yanghuaqings/article/details/47167875
首先,gcd(n-a,n)=gcd(a,n);
假设 gcd(n-a,n)=x 即存在k1,k2,k1!=k2&&gcd(k1,k2)=1使得
n-a=k1*x,n=k2*x;
a=n-k1*x=k2*x-k1*x=(k2-k1)*x;
gcd(n-a,n)=gcd(k1*x,k2*x)=gcd((k2-k1)*x,k2*x)=x;(因为k1!=k2&&gcd(k1,k2)=1);
gcd(n-a,n)*gcd(n-b,n)=n^k;
如果k>2,不存在
如果k==2,只有一种情况a=n,b=n;
如果n==1,只有一种情况
其余情况为k==1的时候
假设 gcd(n-a,n)==x ,那么(n-1)/x 与 n/x 互质,其中 x 与 n 是已知的,即 n/x 是已知的,转化为求小于求与n/x互质的数的个数,
即是欧拉函数 ma=ouler(n/x)
同理可得对 gcd(n-b,n) == n/x; mb=ouler(x);
因为a与b可以转换 2*ma*mb
但是当 x*x==n, ma*mb
#include<iostream>#include<cstdio>#include<cmath>#include<cstring>using namespace std;const long long mod=1e9+7;long long ouler(long long p){ long long ans=p; long long x=sqrt(p); for(int i=2;i<=x;i++) { if(p%i==0) { while(p%i==0) p=p/i; ans=ans/i*(i-1); } } if(p>1) ans=ans*(p-1)/p; return ans;}int main(){ long long n,k; while(~scanf("%I64d%I64d",&n,&k)) { if(n==1) { printf("1\n"); continue; } if(k==2) { printf("1\n"); continue; } if(k>2) { printf("0\n"); continue; } long long ans=0; for(int i=1;i*i<=n;i++) { if(n%i==0) { if(i*i==n) ans+=ouler(i)*ouler(n/i); else ans+=2*ouler(i)*ouler(n/i); ans%=mod; } } printf("%I64d\n",ans); } return 0;}
0 0
- hdu 4983 Goffi and GCD
- HDU 4983 Goffi and GCD(数论)
- hdu 4983 Goffi and GCD(数论)
- hdu 4893 Goffi and GCD
- HDOJ 4983 Goffi and GCD
- hdu 4983 Goffi and GCD(欧拉函数)
- [欧拉函数] hdu 4983 Goffi and GCD
- HDU 4983 Goffi and GCD(数列、欧拉函数)
- HDU 4983/BC 6C Goffi and GCD
- HDU-4983-Goffi and GCD【数论】【欧拉函数】
- HDU4983 Goffi and GCD
- bestcode#6—1003 HDU 4983 Goffi and GCD 【欧拉函数】
- 【欧拉函数】 HDOJ 4983 Goffi and GCD
- bc第六场Goffi and GCD
- HDOJ 题目4983 Goffi and GCD(数学,欧拉函数)
- HDU 4981 Goffi and Median(水)
- hdu 4981 Goffi and Median(水题)
- hdu 4982 Goffi and Squary Partition(构造)
- ssh无密码登录设置出现问题 ECDSA host key 和IP地址对应的key不同的解决
- mysql主从同步延迟优化大全
- HTML中display常用值inline,block与inline-block的区别
- 2551: 表达式求值
- javascript之window对象
- hdu 4983 Goffi and GCD
- pthread_detach
- java 二叉树(十一)表达式与逆波兰序列
- 108---java中的集合
- 用于HTML5移动开发的几大移动APP开发框架
- This TypedArray should be recycled after use with #recycle()为什么需要在TypedArray后调用recycle
- Jquery之Bind方法--参数传递与接收的三种方法
- C++ <algorithm>头文件
- 数据库基础