Multiplying Two Numbers

本文介绍了一个算法挑战,任务是给出两个正整数,通过不断相乘生成一系列数值,并去除重复项后找到第10小的数。示例代码使用C语言实现这一过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Multiplying Two Numbers

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: 1a7, 1b100. 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.
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值