You are not logged in. Please login at www.codechef.com to post your questions!

×

need optimization help..

//Developer : ruhul1995 || Time : 00:58 AM ||Date : 23/11/2017 //how to optimize this code..... i want the program to execute value of 10 power 6 and give the value for fibanacci and factorial...please help

include<iostream>

define MOD 1000000007

using namespace std; const int MAX = 2 * 1000000;

long long int f[MAX] = {0};

long long int fib(long long int n) { / Declare an array to store Fibonacci numbers. /

long long int f[n+1]; long long int i;

/ 0th and 1st number of the series are 0 and 1/ f[0] = 1; f[1] = 1;

for (i = 2; i <= n; i++) {

  f[i] = f[i-1] + f[i-2];

}

return f[n]; }

long long int fact( long long int n) {

if(n == 0 || n == 1)
    return 1 ;

else
    return n*fact(n-1);

}

int main() {

int testcase;

cin>>testcase;
while(testcase--)
{
    long long int n , m , k1 , i , p = 0 , final_answer = 0  ;
    cin>>n>>m>>k1;
    for( i = n ; i <= m ; i++)
    {
        p += fib(i) * fact(i) ;
    }

  //  cout<<"p="<<p<<endl;

    final_answer = p/k1 ; // x * k <= p

    cout<<(final_answer % MOD)<<endl;
}
return 0;

}

asked 23 Nov '17, 01:02

ruhul1995's gravatar image

1★ruhul1995
6717
accept rate: 6%

edited 23 Nov '17, 01:05

can you format the code

(23 Nov '17, 01:04) kunnu1202★

Bro please...

The contest is still live. Don't ask questions related to live competitions here. And moreover you posted your whole code of a live problem.

Contest problem link.

link

answered 23 Nov '17, 02:13

vatsalsura's gravatar image

1★vatsalsura
1659
accept rate: 8%

edited 23 Nov '17, 02:13

toggle preview
Preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:

×228

question asked: 23 Nov '17, 01:02

question was seen: 266 times

last updated: 23 Nov '17, 02:13