32: Sum of score sequences, 32: fractional Sequences

Source: Internet
Author: User

32: Sum of score sequences, 32: fractional Sequences
32: Calculate the fractional sequence and

  • View
  • Submit
  • Statistics
  • Question
Total time limit:
1000 ms
 
Memory limit:
65536kB
Description

There is a fractional sequence q1/p1, q2/p2, q3/p3, q4/p4, q5/p5 ,...., qi + 1 = qi + pi, pi + 1 = qi, p1 = 1, q1 = 2. For example, the first six items of the sequence are 2/1, 3/2, 5/3, 8/5, 13/8, 21/13, respectively. Calculate the sum of the First n items of the fractional sequence.

Input
The input contains a row containing a positive integer n (n <= 30 ).
Output
The output contains a row containing a floating point number, indicating the sum of the First n items in the fractional sequence, which is precise to the fourth digit after the decimal point.
Sample Input
2
Sample output
3.5000
Source
1685
#include<iostream>#include<cstdio>#include<cstring>using namespace std;int ans[10001];double tot=0;int main(){    int n;    cin>>n;    double q=2;    double p=1;    for(int i=1;i<=n;i++)    {        tot=tot+(q/p);        double a=q;        q=a+p;        p=a;    }    printf("%.4lf",tot);    return 0;}

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.