hdoj-1299-Diophantus of Alexandria【判断素因子个数+组合数】

Diophantus of Alexandria

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)

Total Submission(s): 2853 Accepted Submission(s): 1099

Problem Description

Diophantus of Alexandria was an egypt mathematician living in Alexandria. He was one of the first mathematicians to study equations where variables were restricted to integral values. In honor of him, these equations are commonly
called diophantine equations. One of the most famous diophantine equation is x^n + y^n = z^n. Fermat suggested that for n > 2, there are no solutions with positive integral values for x, y and z. A proof of this theorem (called Fermat‘s last theorem) was found
only recently by Andrew Wiles.

Consider the following diophantine equation:

1 / x + 1 / y = 1 / n where x, y, n ∈ N+ (1)

Diophantus is interested in the following question: for a given n, how many distinct solutions (i. e., solutions satisfying x ≤ y) does equation (1) have? For example, for n = 4, there are exactly three distinct solutions:

1 / 5 + 1 / 20 = 1 / 4

1 / 6 + 1 / 12 = 1 / 4

1 / 8 + 1 / 8 = 1 / 4

Clearly, enumerating these solutions can become tedious for bigger values of n. Can you help Diophantus compute the number of distinct solutions for big values of n quickly?

Input

The first line contains the number of scenarios. Each scenario consists of one line containing a single number n (1 ≤ n ≤ 10^9).

Output

The output for every scenario begins with a line containing "Scenario #i:", where i is the number of the scenario starting at 1. Next, print a single line with the number of distinct solutions of equation (1) for the given value of
n. Terminate each scenario with a blank line.

Sample Input

2
4
1260

Sample Output

Scenario #1:
3

Scenario #2:
113

Source

TUD Programming Contest 2006

Recommend

JGShining | We have carefully selected several similar problems for you:
1211 1215 1695 1787 2824

#include<stdio.h>
#include<math.h>
int factor(int n){
	int sqrtn=int(sqrt(n))+1;
	int sum=1;
	for(int div=2;div<=sqrtn;++div){
		int c=0;
		while(n%div==0){
			n/=div;
			++c;
		}
		if(c)
		sum*=(2*c+1);
	}
	if(n>1) sum*=3;
	return sum;
}
int main(){
	int n,t,ncas=0;
	scanf("%d",&t);
	while(t--){
		ncas++;
		scanf("%d",&n);
	    int res=factor(n);
        printf("Scenario #%d:\n",ncas);
		printf("%d\n\n",(res+1)/2);
	}
	return 0;
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

时间: 2024-10-29 04:57:26

hdoj-1299-Diophantus of Alexandria【判断素因子个数+组合数】的相关文章

hdu 1299 Diophantus of Alexandria(数学题)

题目链接:hdu 1299 Diophantus of Alexandria 题意: 给你一个n,让你找1/x+1/y=1/n的方案数. 题解: 对于这种数学题,一般都变变形,找找规律,通过打表我们可以发现这个答案只与这个数的因子有关. n=a1^p1*a2^p2*...*an^pn ans=((1+2*p1)*(1+2*p2)*...*(1+2*pn)+1)/2 1 #include<bits/stdc++.h> 2 #define F(i,a,b) for(int i=a;i<=b;

hdu 1299 Diophantus of Alexandria (数论)

Diophantus of Alexandria Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 2269    Accepted Submission(s): 851 Problem Description Diophantus of Alexandria was an egypt mathematician living in Ale

hdu 1299 Diophantus of Alexandria

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1299 题目大意:就是给你一个n,求1/x+//y=1/n正整数解的个数. 思路:首先我们可以在两边同时乘以xyn得yn+xn=xy,然后因式分解的(x-n)*(y-n)=n*n.这题要求解的个数,就变成了求n*n的因子数,网上很多人都是令y=n+k,然后的x=(n*n)/k+n,这儿也是求n*n的因子数. 通过数论的中的学习我们知道任意一个数n都可以由素数表示出来,即: n=p1^e1*p2^e2*

hdu-1299 Diophantus of Alexandria(分解素因子)

思路: 因为x,y必须要大与n,那么将y设为(n+k);那么根据等式可求的x=(n2)/k+n;因为y为整数所以k要整除n*n; 那么符合上面等式的x,y的个数就变为求能被n*n整除的数k的个数,且k>=n; 那么k就在n到n*n之间,不过这样不则么好求. 因为x,y具有对称性,从y=(n+k)和x=(n2)/k+n;也可以看出(n*n/k,和k等价因为k*(n*n/k)=n*n): 由于任何数都可以拆成素数的乘积,形式为a1^x1*a2^x2*a3*^x3......; 那么因数的个数为(1+

快速判断一个数是否是4的幂次方,若是,并判断出来是多少次方!

将4的幂次方写成2进制形式后,很容易发现有个特点,2进制中只有1个1(1在奇数位置),并且后面跟了偶数个0:因此问题可以转化为判断1后面是否跟了偶数个0就可以了. 4的整数次幂的二进制可以写为2^(2*n),即也可以写成2的幂次方,当然就满足2的幂次方的条件,即num&(num-1)==0. 思路:首先用条件num&(num-1)==0来判断是否为2的幂次方,若不满足,则不是.若满足,再用条件num&0x5555 5555 来判断,若为真,则这个整数是4 的幂次方.否则不是. #i

vuex中filter的使用 &amp;&amp; 快速判断一个数是否在一个数组中

vue中filter的使用 computed: mapState({ items: state => state.items.filter(function (value, index, arr) { return index < 5 }) }), 如上所示,对于vuex,我们在使用mapState获取state时, 可以使用filter来过滤其中的元素,在filter的回调函数中接受三个参数,第一个是value,即每一个元素的值: 第二个是index, 即每一个元素所在的index, 第三个

请编写一个程序,该程序可以接收两个数,并判断两个数是大于、小于、等于?

//作者:janushu //日期:2017/9/20 //功能判断两个数的大小 import java.io.*; public class CompareToNumDemo{ public static void main(String[] args){ try{ //输入流 从键盘上输入一个数 InputStreamReader isr = new InputStreamReader(System.in); //缓存读取一个数 BufferedReader br = new Buffere

判断一个数是否为质数

在软件开发的过程中,很多问题就像是应用题,有很多中解答的方式,但是结果都是一样,然而方式也有更加简单,易懂的. 例如标题所示,判断一个数是否为质数: 1. Static bool IsAdd (int n) { if(n%2!=0) { return true; } else { return false; } } 2. Static bool IsAdd (int n) { if(n%2!=0) { return true: }return false: } 3. Static bool Is

Java基础——使用三元运算符判断一个数的奇偶性

要求: 使用三元运算符判断一个数的奇偶性 实现代码: /** * 使用三元运算符判断用户输入的一个数的奇偶性 */ import java.util.Scanner; public class Odd_even { public static void main(String[] args) { Scanner input = new Scanner(System.in); System.out.println("请输入一个整数:"); long num1 = input.nextLo