天天看点

hdu1012-u Calculate e

http://acm.hdu.edu.cn/showproblem.php?pid=1012

如题,求出n属于0 ~  9 之间所有满足公式的解

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<bitset>
#include<stdlib.h>
#include<iomanip> 
using namespace std;

int main()
{
	int n ;
	double e ;
	cout<< "n e" << endl ;  
    cout<< "- -----------" << endl ;
    cout<< "0 1" << endl ;
    cout<< "1 2" << endl ;
    cout<< "2 2.5" << endl ;
    n = 2 ; 
	e = 2.5 ;
	for( int i = 3 ; i <= 9 ; i++ )
	{
		n *= i ;
		e += 1.0 / n ;
		printf( "%d %.9lf\n" , i , e ) ; 
	} 
	return 0 ;
}