We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Tried implementing using Diatomic Series in C# but it times out. What am I doing wrong?:
usingSystem;usingSystem.Collections.Generic;usingSystem.IO;usingSystem.Linq;usingSystem.Collections;/*f(0) = 0f(1) = 1f(2n) = f(n) , for all even numbersf(2n+1) = f(n) + f(n+1) , for all odd numbers*/classSolution{privatestaticdecimalfn(decimaln){if(n==0||n==1)returnn;elseif(n%2==0)returnfn(n/2);elseif(n%2==1)//oddreturnfn((n-1)/2)+fn((n+1)/2);returnlong.MinValue;}staticvoidMain(String[]args){decimalnum=Convert.ToDecimal(Console.ReadLine());Console.WriteLine(fn(num+1));}}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Project Euler #169: Exploring the number of different ways a number can be expressed as a sum of powers of 2.
You are viewing a single comment's thread. Return to all comments →
Tried implementing using Diatomic Series in C# but it times out. What am I doing wrong?: