September 2021 cohort is finalized with 45 amazing folks. For future cohorts Join the waitlist

MCUR98 Solution



#include <stdio.h>
#define SIZE 1000010

int visited[SIZE] = {0};

int main( int argc , char * argv[] ) {

	int i;
	char str[16];
	for ( i = 1 ; i < 1000000 ; i++ ) {

		if ( visited[i] == 0 )
			printf("%d\n" , i );

		int n = i;
		int sum = 0;
		while ( n != 0 ) {
			sum += (n%10);
			n /= 10;
		}

		if ( i+sum < SIZE )
			visited[i+sum] = 1;
	}
	return 0;
}

470+ Competitive Programming Solutions

If you like what you read subscribe to my newsletter.

I write essays on various engineering topics and share it through my weekly newsletter 👇