UVa : 10879 (Code Refactoring)



// http://uva.onlinejudge.org/external/108/10879.html

// @BEGIN_OF_SOURCE_CODE

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <cctype>
#include <stack>
#include <queue>
#include <list>
#include <vector>
#include <map>
#include <sstream>
#include <cmath>
#include <bitset>
#include <utility>
#include <set>
#define INT_MAX 2147483647
#define INT_MIN -2147483648
#define pi acos(-1.0)
#define N 1000000
using namespace std;

int main ()
{
    int testCase;
    scanf ("%d", &testCase);
    int cases = 0;

    while ( testCase-- ) {
        int k;
        scanf ("%d", &k);

        int len = (int) sqrt (k);
        int output [4];
        int currentIndex = 0;

        for ( int i = 2; i <= len; i++ ) {
            if ( k % i == 0 ) {
                output [currentIndex++] = i;
                output [currentIndex++] = k / i;
                if ( currentIndex == 4 ) break;
            }
        }

        printf ("Case #%d: %d = %d * %d = %d * %d\n",
                 ++cases, k, output [0], output [1], output [2], output [3]);
    }

	return 0;
}

// @END_OF_SOURCE_CODE

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