HDU 5879 Cure(技巧)——2016 ACM/ICPC Asia Regional Qingdao Online

传送门

Problem Description
Given an integer n , we only want to know the sum of 1/k2 where k from 1 to n .
 

Input
There are multiple cases.
For each test case, there is a single line, containing a single positive integer n.
The input file is at most 1M.
 

Output
The required sum, rounded to the fifth digits after the decimal point.
 

Sample Input
  
  
1 2 4 8 15
 

Sample Output
  
  
1.00000 1.25000 1.42361 1.52742 1.58044

题目大意:

给你一个数 n ,让你求 ni=11ii,保留5位小数

解题思路:

这个式子,当 n 足够大的时候,这个式子趋近于 π2/6,所以 yy 一下就行了。

/**
2016 - 09 - 18 下午
Author: ITAK

Motto:

今日的我要超越昨日的我,明日的我要胜过今日的我,
以创作出更好的代码为目标,不断地超越自己。
**/

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <queue>
#include <algorithm>
#include <set>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
const int INF = 1e9+5;
const int MAXN = 1e6+5;
const int MOD = 1e9+7;
const double eps = 1e-7;
const double PI = acos(-1);
using namespace std;
LL Scan_LL()///输入外挂
{
    LL res=0,ch,flag=0;
    if((ch=getchar())=='-')
        flag=1;
    else if(ch>='0'&&ch<='9')
        res=ch-'0';
    while((ch=getchar())>='0'&&ch<='9')
        res=res*10+ch-'0';
    return flag?-res:res;
}
int Scan_Int()///输入外挂
{
    int res=0,ch,flag=0;
    if((ch=getchar())=='-')
        flag=1;
    else if(ch>='0'&&ch<='9')
        res=ch-'0';
    while((ch=getchar())>='0'&&ch<='9')
        res=res*10+ch-'0';
    return flag?-res:res;
}
void Out(LL a)///输出外挂
{
    if(a>9)
        Out(a/10);
    putchar(a%10+'0');
}
char str[MAXN];
int main()
{
    while(~scanf("%s",str))
    {
        int len = strlen(str);
        if(len >= 7)
        {
            puts("1.64493");
            continue;
        }
        int sum = 0;
        for(int i=0; i<len; i++)
            sum = sum*10 + (str[i] - '0');
        if(sum >= 120000)
        {
            puts("1.64493");
            continue;
        }
        double ans = 0.0;
        for(double i=1; i<=sum; i++)
            ans += 1.0/(i*i);
        printf("%.5lf\n",ans);
    }
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值