Problem Description
反素数就是满足对于任意i(0<i<x),都有g(i)<g(x),(g(x)是x的因子个数),则x为一个反素数。现在给你一个整数区间[a,b],请你求出该区间的x使g(x)最大。
Input
第一行输入n,接下来n行测试数据
输入包括a,b, 1<=a<=b<=5000,表示闭区间[a,b].
Output
输出为一个整数,为该区间因子最多的数.如果满足条件有多个,则输出其中最小的数.
Sample Input
3
2 3
1 10
47 359
Sample Output
2
6
240
Hint
2的因子为:1 2
10的因子为:1 2 5 10
#include <iostream>
#include <cmath>
int main(int argc, const char *argv[])
{
int n = 0;
std::cin >> n;
while(n --)
{
int a = 0, b = 0;
std::cin >> a >> b;
int nFind = 0;
int nMax = 0;
for(int i = a;i <= b;++ i)
{
int nYinzi = 0;
int nTemp = floor(sqrt(static_cast<double>(i)));
if(nTemp * nTemp == i)
{
nYinzi -= 1;
}
for(int j = 1;j <= nTemp;++ j)
{
if(i % j == 0)
{
nYinzi += 2;
}
}
if(nYinzi > nMax)
{
nFind = i;
nMax = nYinzi;
}
}
std::cout << nFind << std::endl;
}
//system("pause");
return 0;
}