hdu 1299

这个方法太厉害了 别人的记录一下


#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,码迷,mamicode.com

时间: 2024-11-07 11:09:19

hdu 1299的相关文章

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 数论 分解素因子

题意:求1.1/x+1/y=1/z 给定z 求x,y的个数zsd:1: 要知道这个素数的因子的范围 范围为2--sqrt(n);2: 带入方程得: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

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*

HDU1299&amp;&amp;SPOJ - KPEQU(找因子来找解的个数)

题目链接:HDU 1299 传送门 题意: 求方程1/x+1/y=1/n的解的个数 1/3+1/2 与1/2+1/3看作是一组解. 分析: 1/x+1/y = 1/n 设y = n + k; ==>1/x + 1/(n+k)=1/n; ==>x = n^2/k + n; 因为x为整数,k就是n^2的约数. 代码如下: #include <iostream> #include <cstring> #include <cstdio> #include <a

HDU分类

模拟题, 枚举 1002 1004 1013 1015 1017 1020 1022 1029 1031 1033 1034 1035 1036 1037 1039 1042 1047 1048 1049 1050 1057 1062 1063 1064 1070 1073 1075 1082 1083 1084 1088 1106 1107 1113 1117 1119 1128 1129 1144 1148 1157 1161 1170 1172 1177 1197 1200 1201 12

转载:hdu 题目分类 (侵删)

转载:from http://blog.csdn.net/qq_28236309/article/details/47818349 基础题:1000.1001.1004.1005.1008.1012.1013.1014.1017.1019.1021.1028.1029. 1032.1037.1040.1048.1056.1058.1061.1070.1076.1089.1090.1091.1092.1093. 1094.1095.1096.1097.1098.1106.1108.1157.116

HDU 5179 beautiful number 离线处理

传送门:http://acm.hdu.edu.cn/showproblem.php?pid=5179 beautiful number Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 176    Accepted Submission(s): 104 Problem Description Let A=∑ni=1ai?10n?i(1≤

HDU——1573 X问题

X问题 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 6716    Accepted Submission(s): 2340 Problem Description 求在小于等于N的正整数中有多少个X满足:X mod a[0] = b[0], X mod a[1] = b[1], X mod a[2] = b[2], …, X mo