eolymp
bolt
Try our new interface for solving problems
Məsələlər

Acgöz Əziz

dərc olunub 12.01.24 19:03:38
#include <bits/stdc++.h> //including necessary libraries
using namespace std; //using std
map<long long, long long> mp; //main map for storing old values
long long f(long long n){ //define a function with large f and large n
    if(n == 0){ //if the value is 0
        return 1; //function will be 1
    } //stop 0 checking and returning 1
    else if(mp.find(n) != mp.end()){ //if the value is already inside of the map
        return mp[n]; //function will be itself
    } //stop checking if the value is already inside of the map
    else{ //else if the value is not equal to 0 and is not inside of the map
        mp[n] = f(n / 2) + f(n / 3); //the map of value will equal to a new equation and then add the result into the map
        return mp[n]; //function will be itself
    } //stop else condition of checking
} //stop the defined function
int main(){ //main code function start
    ios_base::sync_with_stdio(false); //speeding up the code
    cin.tie(NULL); //speeding up the code
    long long n; //main value
    cin>>n; //get the main value
    cout<<f(n)<<endl; //start the function of main value
    return 0; //speeding up the code
} //main code function end

Solution in C++ using map and with explanations