UVa : 11728


//============================================================================
// Name        : UVa_11728.cpp
// Author      : Shahab
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <string>
using namespace std;

int sumOfFactors (int n)
{
	int output = 1;

	for ( int i = 2; i < n; i++ ) {
		if ( n % i == 0 )
			output += i;
		if ( output > 1000 )
			break;
	}

	if ( n != 1 )
		output += n;

	return output;
}

int main() {
	int save [1000 + 5];
	memset (save, -1, 1005 * sizeof (int));

	int sof;
	int cases = 0;

	for ( int i = 1; i <= 1000; i++ ) {
		sof = sumOfFactors (i);
		if ( sof <= 1000 )
			save [sof] = i;
	}

	int s;

	while ( scanf ("%d", &s) && s ) {
		printf ("Case %d: %d\n", ++cases, save [s]);
	}

	return 0;
}

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s