Everybody knows that we use decimal notation, i.e. the base of our notation is 10. Historians say that it is so because men have ten fingers. Maybe they are right. However, this is often not very convenient, ten has only four divisors -- 1, 2, 5 and 10. Thus, fractions like 1/3, 1/4 or 1/6 have inconvenient decimal representation. In this sense the notation with base 12, 24, or even 60 would be much more convenient.
The main reason for it is that the number of divisors of these numbers is much greater -- 6, 8 and 12 respectively. A good quiestion is: what is the number not exceeding n that has the greatest possible number of divisors? This is the question you have to answer.
Input:
The input consists of several test cases, each test case contains a integer n (1 <= n <= 1016).
Output:
For each test case, output positive integer number that does not exceed n and has the greatest possible number of divisors in a line. If there are several such numbers, output the smallest one.
Sample Input:10 20 100Sample Output:
6 12 60
题意:求小于等于n的约数多的数,若约数相等求输出最小的
题解:long long 在zoj不知道是什么鬼格式。。。于是用cin过了。。。
这里有详细 http://blog.csdn.net/shiren_bod/article/details/5738537
#include<iostream>
using namespace std;
long long prim[18]={1,2,3,5,7,11,13,17,19,23,29,31,37,41,43,47};
long long n,res,cou;
void dfs(long long num,int k,long long sum,int limit)
{
if(sum>cou) cou=sum,res=num;
else if(sum==cou&&num<res) res=num;
if(k>15) return;
long long temp=num;
for(int i=1;i<=limit;i++)
{
temp=temp*prim[k];
if(temp>n) break;
dfs(temp,k+1,sum*(i+1),i);
}
}
int main()
{
ios::sync_with_stdio(false);
while(cin>>n)
{
cou=0,res=n;
dfs(1,1,1,50);
cout<<res<<endl;
}
return 0;
}