Analysis of C/C++ (level 3) real questions in December 2023 #中国 Electronics Society # National Youth Software Programming Level Examination

Insert image description here

C/C++ Programming (Levels 1~8) All real questions・Click here

Question 1: Factor problem

Given two positive integers N and M, find the smallest positive integer a such that a and (Ma) are both factors of N.
Time limit: 10000
Memory limit: 65536
Input
includes two integers N and M. N does not exceed 1,000,000.
Output
Output an integer a, representing the result. If a positive integer that meets the condition does not exist in a certain case, then output -1 in the corresponding line.
Example input
35 10
Example output
5

Answer:

To find the smallest positive integer a such that a and (Ma) are both factors of N, you can use a loop to try from 1 to N. For each number a, we can check whether a is a factor of N, and whether (Ma) is also a factor of N.

Here is an example of C code that solves this problem:

#

Supongo que te gusta

Origin blog.csdn.net/gozhuyinglong/article/details/135435927
Recomendado
Clasificación