Diophantus of Alexandria

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 3242 Accepted Submission(s): 1287

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

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<bitset>
#include<iomanip> using namespace std; #define MAX_PRIME 31700
#define PRIME_NUM 3500 int Primes[ PRIME_NUM + ] ; int _Count = ;
int GetPrimes( )
{
unsigned char *PrimeBuffer = ( unsigned char * ) malloc( sizeof( unsigned char ) * ( MAX_PRIME + ) ) ;
int i , j ; memset( Primes , , sizeof( int ) *PRIME_NUM ) ;
memset( PrimeBuffer , , sizeof( unsigned char) * MAX_PRIME ) ; for( i = ; i < MAX_PRIME ; i++ )
{
if( PrimeBuffer[ i ] == )
Primes[ _Count++ ] = i ;
for( j = ; j < _Count && i * Primes[ j ] <= MAX_PRIME ; j++ )
{
PrimeBuffer[ i * Primes[ j ] ] = ;
if( i % Primes[ j ] == )
break ;
}
}
free( PrimeBuffer ) ;
return _Count ;
} int main()
{
GetPrimes();
int Case , n , num , sum , temp;
cin >> Case ;
temp = ;
while( Case-- )
{
cin >> n ;
sum = ;
for( int i = ; i < _Count ; ++i )
{
int flag = ( int )sqrt( n ) + ;
if( Primes[ i ] > flag )
break ;
num = ;
while( n % Primes[ i ] == )
{
num++ ;
n /= Primes[ i ] ;
}
sum *= ( + * num ) ;
}
if( n > )
sum *= ;
cout << "Scenario #" << ++temp << ":" << endl ;
cout << ( sum + ) / << endl << endl ;
}
return ;
}

Diophantus of Alexandria[HDU1299]的更多相关文章

  1. hdu 1299 Diophantus of Alexandria (数论)

    Diophantus of Alexandria Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java ...

  2. hdu Diophantus of Alexandria(素数的筛选+分解)

    Description Diophantus of Alexandria was an egypt mathematician living in Alexandria. He was one of ...

  3. hdu 1299 Diophantus of Alexandria(数学题)

    题目链接:hdu 1299 Diophantus of Alexandria 题意: 给你一个n,让你找1/x+1/y=1/n的方案数. 题解: 对于这种数学题,一般都变变形,找找规律,通过打表我们可 ...

  4. hdoj 1299 Diophantus of Alexandria

    hdoj 1299 Diophantus of Alexandria 链接:http://acm.hdu.edu.cn/showproblem.php?pid=1299 题意:求 1/x + 1/y ...

  5. Diophantus of Alexandria

    Diophantus of Alexandria was an egypt mathematician living in Alexandria. He was one of the first ma ...

  6. 数学--数论--HDU 1299 +POJ 2917 Diophantus of Alexandria (因子个数函数+公式推导)

    Diophantus of Alexandria was an egypt mathematician living in Alexandria. He was one of the first ma ...

  7. Diophantus of Alexandria(唯一分解定理)

    Diophantus of Alexandria was an Egypt mathematician living in Alexandria. He was one of the first ma ...

  8. 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 ...

  9. hdu 1299 Diophantus of Alexandria

    1/x + 1/y = 1/n 1<=n<=10^9给你 n 求符合要求的x,y有多少对 x<=y// 首先 x>n 那么设 x=n+m 那么 1/y= 1/n - 1/(n+ ...

随机推荐

  1. js函数动态传参

    js函数体内可以通过arguments对象来接收传递进来的参数,利用这一对象属性可以动态传参. function box() { return arguments[0]+' | '+arguments ...

  2. ZOJ 2136 Longest Ordered Subsequence

    #include<time.h> #include <cstdio> #include <iostream> #include<algorithm> # ...

  3. JavaScript基础——使用运算符

    JavaScript运算符允许你改变一个变量的值.你已经熟悉了用于赋值给变量的=运算符.JavaScript提供了几种不同的运算符,它们可以划分为两大类:算数运算符和赋值运算符. 1.算数运算符 你可 ...

  4. jq点击和鼠标移上效果以及一个等号"=" 二个等号"==" 三个等号"===" 的区别

    <body> <div class="a" bs='1' style="width:100px; height:30px; border:1px sol ...

  5. Delphi版本顺序

    1.02.03.04.05.06.07.08.0200520062007 现在应该又出新的版本了

  6. 网站对话框开源脚本--ArtDialog V6.0

    初识对话框脚本觉得artDialog还是挺不错的开源的js脚本,最新版本都是V6.0 ,相对之前版本,artDialog的语法也发生很大的变化,windows对应的JS版本如下 点击下载 语法也发生变 ...

  7. Java 8新特性

    Java 8版本最大的改进就是Lambda表达式,其目的是使Java更易于为多核处理器编写代码:其次,新加入的Nashorn引擎也使得Java程序可以和JavaScript代码互操作:再者,新的日期时 ...

  8. 【openGL】画正弦函数图像

    #include "stdafx.h" #include <GL/glut.h> #include <stdlib.h> #include <math ...

  9. Xcode 缓存 帮助文档 隐藏文件夹显示方法

    删除Xcode的缓存路径是:/Users/用户名/Library/Developer/Xcode/DerivedData(默认情况下, 这是一个隐藏文件夹) 显示隐藏文件夹 指令如下:显示隐藏文件: ...

  10. java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory 解决方案

    缺少 commons-logging.jar