Help me in solving COINS problem

My issue

where my code fails

My code

#include <iostream>
using namespace std;

int main(){
    long n;
    while(cin>>n){
        long m = n/2 + n/3 + n/4 ;
        if (m > n) n=m;
        cout<<n<<endl;
    }
}

Problem Link: COINS Problem - CodeChef

@raman067
U have to divide till u get the maximum coins .
which u can achieve recursively like this.

#include <iostream>
using namespace std;

long solve(long n)
 {
    if(n>=12)
    return solve(n/2) + solve(n/3)+ solve( n/4);
    else
    return n;
    
}
int main() {
     long n; 
     while(cin>>n)
     cout<<solve(n)<<endl;
	
	return 0;
}