hdu1299-Diophantus of Alexandria(分解素因子)
2013-07-23 08:44
253 查看
http://acm.hdu.edu.cn/showproblem.php?pid=1299
题意:给定一个数值n,求满足1/ x + 1/ y = 1 /n的x,y 的组数,又因为x,y一定大于n 。所以设y = n + k ;
带入方程得:x = n * n / k + n ;
现在就变成了求x的值。又因为n一定大于k,所以转换成求n * n的分解数;
因为n = p1 ^ e1 * p2 ^ e2 *..........*pn ^ en
sum ( n)= ( 1 + e1 ) * ( 1 +e2 ) * .........* ( 1 +en );
sum (n * n) = ( 1 + e1 ) * (1 + e2 ) *......* ( 1 + en ) ;
#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 + 10 ] ;
int _Count = 0 ;
int GetPrimes( )
{
unsigned char *PrimeBuffer = ( unsigned char * ) malloc( sizeof( unsigned char ) * ( MAX_PRIME + 10 ) ) ;
int i , j ;
memset( Primes , 0 , sizeof( int ) *PRIME_NUM ) ;
memset( PrimeBuffer , 0 , sizeof( unsigned char) * MAX_PRIME ) ;
for( i = 2 ; i < MAX_PRIME ; i++ )
{
if( PrimeBuffer[ i ] == 0 )
Primes[ _Count++ ] = i ;
for( j = 0 ; j < _Count && i * Primes[ j ] <= MAX_PRIME ; j++ )
{
PrimeBuffer[ i * Primes[ j ] ] = 1 ;
if( i % Primes[ j ] == 0 )
break ;
}
}
free( PrimeBuffer ) ;
return _Count ;
}
int main()
{
GetPrimes();
int Case , n , num , sum , temp;
cin >> Case ;
temp = 0 ;
while( Case-- )
{
cin >> n ;
sum = 1 ;
for( int i = 0 ; i < _Count ; ++i )
{
int flag = ( int )sqrt( n ) + 1 ;
if( Primes[ i ] > flag )
break ;
num = 0 ;
while( n % Primes[ i ] == 0 )
{
num++ ;
n /= Primes[ i ] ;
}
sum *= ( 1 + 2 * num ) ;
}
if( n > 1 )
sum *= 3 ;
cout << "Scenario #" << ++temp << ":" << endl ;
cout << ( sum + 1 ) / 2 << endl << endl ;
}
return 0 ;
}
题意:给定一个数值n,求满足1/ x + 1/ y = 1 /n的x,y 的组数,又因为x,y一定大于n 。所以设y = n + k ;
带入方程得:x = n * n / k + n ;
现在就变成了求x的值。又因为n一定大于k,所以转换成求n * n的分解数;
因为n = p1 ^ e1 * p2 ^ e2 *..........*pn ^ en
sum ( n)= ( 1 + e1 ) * ( 1 +e2 ) * .........* ( 1 +en );
sum (n * n) = ( 1 + e1 ) * (1 + e2 ) *......* ( 1 + en ) ;
#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 + 10 ] ;
int _Count = 0 ;
int GetPrimes( )
{
unsigned char *PrimeBuffer = ( unsigned char * ) malloc( sizeof( unsigned char ) * ( MAX_PRIME + 10 ) ) ;
int i , j ;
memset( Primes , 0 , sizeof( int ) *PRIME_NUM ) ;
memset( PrimeBuffer , 0 , sizeof( unsigned char) * MAX_PRIME ) ;
for( i = 2 ; i < MAX_PRIME ; i++ )
{
if( PrimeBuffer[ i ] == 0 )
Primes[ _Count++ ] = i ;
for( j = 0 ; j < _Count && i * Primes[ j ] <= MAX_PRIME ; j++ )
{
PrimeBuffer[ i * Primes[ j ] ] = 1 ;
if( i % Primes[ j ] == 0 )
break ;
}
}
free( PrimeBuffer ) ;
return _Count ;
}
int main()
{
GetPrimes();
int Case , n , num , sum , temp;
cin >> Case ;
temp = 0 ;
while( Case-- )
{
cin >> n ;
sum = 1 ;
for( int i = 0 ; i < _Count ; ++i )
{
int flag = ( int )sqrt( n ) + 1 ;
if( Primes[ i ] > flag )
break ;
num = 0 ;
while( n % Primes[ i ] == 0 )
{
num++ ;
n /= Primes[ i ] ;
}
sum *= ( 1 + 2 * num ) ;
}
if( n > 1 )
sum *= 3 ;
cout << "Scenario #" << ++temp << ":" << endl ;
cout << ( sum + 1 ) / 2 << endl << endl ;
}
return 0 ;
}
相关文章推荐
- HDU-1299 Diophantus of Alexandria 素因子分解
- hdu-1299 Diophantus of Alexandria(分解素因子)
- Diophantus of Alexandria(求一一个数的因子个数)
- HDU 1299 Diophantus of Alexandria 求因子个数
- Diophantus of Alexandria[HDU1299]
- HDU1299 Diophantus of Alexandria
- hdoj-1299-Diophantus of Alexandria【判断素因子个数+组合数】
- hdu Diophantus of Alexandria(求因子的个数)
- HDU 1299 Diophantus of Alexandria (公式变形 分解质因数)
- hdu1299 Diophantus of Alexandria(数学题)
- HDU-1299 Diophantus of Alexandria(数论:因子数)
- poj 2917 Diophantus of Alexandria 因数分解解1/x+1/y=1/n
- hdu 1299 Diophantus of Alexandria(数论(因子个数和))
- HDU 1299 Diophantus of Alexandria
- hdu 1299 Diophantus of Alexandria
- 【HDU】 1299 Diophantus of Alexandria
- HDOJ-1299-Diophantus of Alexandria 解题报告
- Hoj 2305 Diophantus of Alexandria
- hdoj 1492 The number of divisors(约数) about Humble Numbers 【数论】【质因子分解 求和】
- HDU 1299 Diophantus of Alexandria