SPOJ Equation :求 1/n!=1/x+1/y 的解的个数
来源:互联网 发布:前苏联挖到地狱知乎 编辑:程序博客网 时间:2024/06/06 00:05
Description
You are given integer positive number N. Find the number of solutions in positive integer numbers of the following equation:
Input
Each line of input file contains one integer number N (1 ≤ N ≤ 104). The last line contains 0 and shouldn't be processed. Number of lines in the input does not exceed 30.
Output
For every line in the input write the answer on a separate line.
Sample Input
Input:120Output:13
//题目就是求1/n! = 1/x + 1/y 的解的个数,看样例知要考虑(x,y)对数的关系。
//设 m=n! ,由等式知x,y必定大于n!,所以再设 x=n!+k=m+k 带入 1/m=1/x+1/y 中化简得到y=m*m/k+m,因y为整数,所以要求k整除m*m,即k为m*m的因子,问题便转化为求n!*n!的因子个数, 设n!=p1^e1 * p2^e2 * p3^e3 *...*pk^ek,则 n!*n!= p1^(2*e1) * p2^(2*e2) *...*pk^(2*ek) 。 则因子个数sum=(2*e1+1)*(2*e2+1)*...*(2*ek+1); 答案很大,需要高精度。用java处理方便!
import java.util.Scanner; import java.io.*; import java.math.*; import java.math.BigInteger; public class Main { static boolean x[]=new boolean[10000+10]; static int prime[]=new int[10000+10],num[]=new int[10000+10],cnt=0; public static void Init() { int i,tmp; for(i=0;i<=10000;i++) x[i]=false; x[0]=x[1]=true; for(i=2;i<=10000;i++) if(x[i]==false) { prime[++cnt]=i; tmp=i*i; while(tmp<=10000) { x[tmp]=true; tmp+=i; } } } public static void main(String[] args) { Scanner cin=new Scanner(System.in); Init(); int n,i,tmp; while(cin.hasNext()) { n=cin.nextInt(); if(n==0) break; for(i=0;i<=10000;i++) num[i]=0; for(i=1;i<=cnt&&prime[i]<=n;i++) //分解出n!内所有因子的个数 { tmp=n; while(true) { if(tmp==0||(prime[i]>n)) break; num[i]+=tmp/prime[i]; tmp/=prime[i]; } } BigInteger ans=BigInteger.ONE; for(i=1;i<=cnt&&prime[i]<=n;i++) if(num[i]>=1) ans=ans.multiply(BigInteger.valueOf(2*num[i]+1)); System.out.println(ans); } } }
- SPOJ Equation :求 1/n!=1/x+1/y 的解的个数
- SPOJ Equation :求 1/n!=1/x+1/y 的解的个数
- 求1/X+1/Y= 1/N的所有正整数解
- 求区间x∈[1,n],y∈[1,m],gcd(x,y)=1的数量 [容斥]
- 【欧拉函数 && 求gcd(n, x) = y,x的个数】UVA
- bzoj 4152 the camptin (dis[x][y]=min(|x.x-y.x|,|x.y-y.y|),求1,n最短路)
- 求28 * x + 15 * y = 95108的所有x与y的整数值个数
- 求指定分段函数y=x-1(x>1);y=-x+1(x<=1)的输出
- (x&y) + ( (x^y)>>1 )求平均值
- 求特征数列(第n个数是第n-1个数和第n-2个数的和)的第X个数是多少
- 求 1~n 之间素数的个数
- 求两个整型数的平均值:return (x&y) + ((x^y)>>1)
- 1/X+1/Y=1/N!的两种O(n)做法
- 求(1~n)个数中1的个数
- SPOJ - VLATTICE Visible Lattice Points(gcd(x,y,z)=1的对数/莫比乌斯反演)
- 省赛i题/求1~n内所有数对(x,y),满足最大公约数是质数的对数
- 求n个数(1~n)的质因子
- hdu4282 x^z+y^z+x*y*z=k 解的个数
- 编程之美1.3 代码实现
- 高手DOS命令下的系统维护
- servlet路径匹配
- adb命令
- ARM 开发板 ssh 移植
- SPOJ Equation :求 1/n!=1/x+1/y 的解的个数
- Flex入门(一)简介和安装
- 童年时光,被遗忘的俄罗斯方块
- Linux下C语言编程基础 —— Makefile
- Flex技巧收集
- poj1041
- WMI在VC中的使用 -- 设置DHCP和DNS
- Mario开发流程(五)
- 关于oracle与mysql官方jdbc的一些区别