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