Search
 
SCRIPT & CODE EXAMPLE
 

CPP

primtiive calculator in c++

#include <iostream>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <stdlib.h>

long long f(long long n, vector <long long> arr)
{ 
    arr[1]=0;

    arr.push_back(n);
    long long ans=0, ret=0;

    if (n==1)
    {
        return (0);
    }
    ans= f(n-1, arr) + 1;


    if (n%2==0)
    {
        ret= f(n/2, arr) + 1;
        if (ret<ans)
        {
            ans=ret;
            std::cout<<ans<<'
';
        }
    }
    if (n%3==0)
    { 
        ret= f(n/3, arr) + 1;
        if (ret<ans)
        {
            ans=ret;
            std::cout<<ans<<'
';
        }
    }
    arr[n]=ans;

    return arr[n];    
}

int main() {

    long long n;
    std::cin >> n;
    std::vector<long long> arr;
    std::cout<<f(n, arr);

    return 0;
}
Comment

PREVIOUS NEXT
Code Example
Cpp :: Difference Array | Range update query in O 
Cpp :: transform c++ 
Cpp :: fishes code in assignment expert 
Cpp :: C++ singleton prevent copy 
Cpp :: code::block uncomment 
Cpp :: Imports the elements in the array c++ 
Cpp :: assign array to array 
Cpp :: how to get max grade c++ 
Cpp :: C++ Array With Empty Members 
Cpp :: c++ start process and get output 
Cpp :: i++ and++i 
Cpp :: 28+152+28+38+114 
Cpp :: how to calculate marks in C++ 
Cpp :: second smallest element using single loop 
Cpp :: convert string to wide string 
Cpp :: days in a year c++ 
Cpp :: find largest number in each row in array c++ using function 
Cpp :: c++ to c converter online 
Cpp :: MPI_Sendrecv 
Cpp :: convert c++ to python online 
Cpp :: std::throw_with_nested 
Cpp :: c++ code 2d block 
Cpp :: c++ switch integer 
Cpp :: construct string with repeat limit 
Cpp :: Change Font ImGui 
Cpp :: Marin and Anti-coprime Permutation codeforces solution in c++ 
Cpp :: Chef and Feedback codechef solution in cpp 
Cpp :: c++ convert const char* to LPCWSTR 
Cpp :: fenwick tree 
Cpp :: string to wstring conversion c++ 
ADD CONTENT
Topic
Content
Source link
Name
7+4 =