Luogu P1372 is also the graduation season I (Shang Xian)

Title Portal

After simplifying this question, what we are seeking is: take k numbers from 1 to n to maximize the greatest common divisor of these k numbers

Because when the two numbers are in a multiple relationship, their greatest common factor is the smaller of the two numbers, that is, the greatest common factor is relatively large

Back to the question, these k numbers are actually: x * 1, x * 2 ... x * k, and 1 ~ k times of x, but it must be ensured that x * k is less than n, under the above conditions, can I know that the largest x that meets the condition is the answer. In order to find the largest x, x * k must be as close to n as possible, because the integer division of c ++ has the function of automatic rounding, so in all cases, n / k is the final answer

 

AC code

#include <iostream>
#include <cstdio>
using namespace std;
int main() {
	freopen("cpp.in", "r", stdin);
	freopen("cpp.out", "w", stdout);
	int x, y;
	scanf("%d%d", &x, &y);
	printf("%d\n", x / y);
	return 0;
} 

 

Posted 33 original articles · liked 0 · visits 167

Guess you like

Origin blog.csdn.net/weixin_42790071/article/details/105539903