PROBLEM LINK :
Author : Vibhor Gupta
Tester : Vibhor Gupta
Editorialist : Vibhor Gupta
Rahul ha been given a string containing space separated integers. He does not know how many integers are in the string.
He has also been given 2 integers a,b. He has to make a fibonacci type of sequence with it. i.e nth term is sum of (n-1)th term and (n-2)th term.
Finally he has to calculate the sum of the nth integer in the above sequence for every integer n in the string.
As the output can be large, print the answer modulo 10^9 + 7
Flawed Code :
#define gl(x) getline(cin,x);
using namespace std;
long long fib;
for(int i=2;i!=1000000;i++) fib[i] = (fib[i-1]+fib[i-2])%mod;
while(ss>>x)sum += fib[x];
This question was quite simple, the main challenge was to take input of an unknown number of integers.
The normal cin could not be used as it would eat up the next test case also.
This problem was solved using the Stringstream function.
The corrected code can be view at, Corrected Solution