欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 新闻 > 会展 > B. Maximum Multiple Sum

B. Maximum Multiple Sum

2026/5/26 10:48:56 来源:https://blog.csdn.net/jj12345jj198999/article/details/139871424  浏览:    关键词:B. Maximum Multiple Sum

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Given an integer n𝑛, find an integer x𝑥 such that:

  • 2≤x≤n2≤𝑥≤𝑛.
  • The sum of multiples of x𝑥 that are less than or equal to n𝑛 is maximized. Formally, x+2x+3x+⋯+kx𝑥+2𝑥+3𝑥+⋯+𝑘𝑥 where kx≤n𝑘𝑥≤𝑛 is maximized over all possible values of x𝑥.

Input

The first line contains t𝑡 (1≤t≤1001≤𝑡≤100) — the number of test cases.

Each test case contains a single integer n𝑛 (2≤n≤1002≤𝑛≤100).

Output

For each test case, output an integer, the optimal value of x𝑥. It can be shown there is only one unique answer.

Example

input

Copy

 

2

3

15

output

Copy

3
2

Note

For n=3𝑛=3, the possible values of x𝑥 are 22 and 33. The sum of all multiples of 22 less than or equal to n𝑛 is just 22, and the sum of all multiples of 33 less than or equal to n𝑛 is 33. Therefore, 33 is the optimal value of x𝑥.

For n=15𝑛=15, the optimal value of x𝑥 is 22. The sum of all multiples of 22 less than or equal to n𝑛 is 2+4+6+8+10+12+14=562+4+6+8+10+12+14=56, which can be proven to be the maximal over all other possible values of x𝑥.

解题说明:此题是一道数学题,为了保证x的倍数之和尽可能大,同时kx小于n,则x应该尽可能小,求和的值为(1+k)/2 * kx  而kx小于n ,就要保证k值越大越好,那么很显然x越小k值容易越大。x最小 为2。此时要区分n为3的情况,此时x为3为最优解。

#include<stdio.h>int main()
{int t;scanf("%d", &t);while (t--){int n;scanf("%d", &n);if (n == 3){printf("3\n");}else{printf("2\n");}}return 0;
}

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

热搜词