hdu1299-Diophantus of Alexandria(分解素因子)

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 ;
}


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值