Algorithm
Code Examples
#1 Code Example with C++ Programming
Code -
C++ Programming
#include <cstdio>
int main(){
long n(0); scanf("%ld", &n);
long numSevens(-1), numFours(-1), minDigits(1e6);
for(long testSevens = n / 7; testSevens >= 0; testSevens--){
if((n - 7 * testSevens) % 4 != 0){continue;}
long testFours = (n - 7 * testSevens) / 4;
numSevens = testSevens; numFours = testFours;
minDigits = numSevens + numFours;
break;
}
Copy The Code &
Try With Live Editor
Input
11
Output
47
Demonstration
Codeforces Solution-A. Lucky Sum of Digits-Solution in C, C++, Java, Python