This is a solution I found to a CodeForces problem 919B - Perfect Number. I technically understand what it is doing but I want to understand the 'intuition' behind it or the idea/approach.
int main(){
int k=0, m=19, c=0, sum=0;
scanf("%d", &k);
while(true){
int n = m;
sum = 0;
while(n){
sum+=n%10;
n=n/10;
}
printf("%d %d %d\n", n, sum, c);
if(sum == 10) c++;
if(c == k) break;
m++;
}
printf("%d", m);
return 0;
}
Aucun commentaire:
Enregistrer un commentaire