Two positive integers are given. You create numbers by multiplying these numbers.
For example, assume that 4 and 20 are given. When you list numbers you can create in order of size by multiplying these numbers, the order will be 4, 4*4, 20, 4*4*4, 4*20...
When 5 and 7 are given, the order will be 5, 7, 5*5, 5*7, ....
When 2 and 100 are given, the order will be 2, 22, 23, 24, 25, 26, 100, 27, 2*100, 28, ..., so, the 10th smallest number is 28=256.
Duplication in created numbers can happen. For instance, when 2 and 4 are given. the order of the list goes 2, 22, 4, 2*4, 23... but, 22 and 4 are the same and so are 2*4 and 23.
In this case, consider them as one. In other words, the order of multiplied numbers has to be listed as 2, 4, 8, 16, 32, ... after removing duplication, so the 5th smallest number is 32, not 8.
When two positive integers are given, write a program that finds the 10th smallest number among the created numbers through multiplication of the two integers.
All numbers as input are given in a way that does not cause overflow within integer range (231-1 or less).
[Constraints]
Two integers a and b fall into the following category: 1≤a≤7, 1≤b≤100. In other words, the first integer is 7 or less and the second integer is 100 or less.
[Input]
10 test cases are given. Throughout 10 lines, one test case is given in one line each. Each test case consists of two integers a and b. The two numbers are distinguished by a white space.
[Output]
Print answers to each of the 10 test cases in 10 lines in total. Start each line with "#x" (x: number of test case), leave a white space, and write the answer.
[Input/output example]
Input (consisting of 10 lines in total)
/*You should use the statndard input/output
in order to receive a score properly.
Do not use file input and output
Please be very careful. */
#include <stdio.h>
#include "stdafx.h"
#define MAX_A 11
int Answer;
int a,b;
int Array_A[MAX_A];
int Array_B[MAX_A];
int Array_P[MAX_A];
int i=0;
int Result=1;
//Array_A[0]=1;
void find(int a,int b)
{
//for(;i<11;i++)
if(i<11)
{
if(i == 0)Array_A[0]=1;
if(a<=b)
{
//Array_A[i]= a;
Array_A[i]=Array_A[i]*a;
i++;
find(a,b);
}
if(a>b)
{
//Array_A[i]= b;
Array_A[i]=Array_A[i]*b;
i++;
find(a,b);
}
/*else{
Array_A[i]= b;
i++;
}*/
}
}
int main(void)
{
int T, test_case;
int i;
/*
The freopen function below opens input.txt file in read only mode, and afterward,
the program will read from input.txt file instead of standard(keyboard) input.
To test your program, you may save input data in input.txt file,
and use freopen function to read from the file when using scanf function.
You may remove the comment symbols(//) in the below statement and use it.
But before submission, you must remove the freopen function or rewrite comment symbols(//).
*/
// freopen("input.txt", "r", stdin);
/*
If you remove the statement below, your program's output may not be rocorded
when your program is terminated after the time limit.
For safety, please use setbuf(stdout, NULL); statement.
*/
//setbuf(stdout, NULL);
//scanf("%d", &T);
T = 1;
for(test_case = 0; test_case < T; test_case++)
{
//scanf("%d %d",&a , &b);
a=2,b=5;
find(a,b);
/////////////////////////////////////////////////////////////////////////////////////////////
/*
Implement your algorithm here.
The answer to the case will be stored in variable Answer.
*/
/////////////////////////////////////////////////////////////////////////////////////////////
Answer = 0;
Answer = Array_A[10];
// Print the answer to standard output(screen).
printf("Case #%d\n", test_case+1);
printf("%d\n", Answer);
}
return 0;//Your program should return 0 on normal termination.
}