1748. The Most Complex Number
Time limit: 1.0 second
Memory limit: 64 MB
Memory limit: 64 MB
Let us define a complexity of an integer as the number of its divisors. Your task is to find the most complex integer in range from 1 to n. If there are many such integers, you should find the minimal one.
Input
The first line contains the number of testcases t (1 ≤ t ≤ 100). The i-th of the following t lines contains one integer ni (1 ≤ ni ≤ 1018).
Output
For each testcase output the answer on a separate line. The i-th line should contain the most complex integer in range from 1 to ni and its complexity, separated with space.
Sample
input | output |
---|---|
5 1 10 100 1000 10000 |
1 1 6 4 60 12 840 32 7560 64 |
Problem Author: Petr Lezhankin
Problem Source: Ufa SATU Contest. Petrozavodsk Summer Session, August 2009
题目大意:一个数的因子的个数为它的复杂度,求[1, n]间因子最多的数, 以及该数因子的个数
思路:有个公式。。
N = p1a1*p2a2*p3a3*p4a4,有a1>= a2 >= a3 >= a4, p1,p2, p3, p4为质数
number = (1+a1)*(1+a2)*(1+a3)*(1+a4)
#include <iostream> #include <sstream> #include <fstream> #include <string> #include <vector> #include <deque> #include <queue> #include <stack> #include <set> #include <map> #include <algorithm> #include <functional> #include <utility> #include <bitset> #include <cmath> #include <cstdlib> #include <ctime> #include <cstdio> #include <cstring> #define FOR(i, a, b) for(int i = (a); i <= (b); i++) #define RE(i, n) FOR(i, 1, n) #define FORP(i, a, b) for(int i = (a); i >= (b); i--) #define REP(i, n) for(int i = 0; i <(n); ++i) #define SZ(x) ((int)(x).size ) #define ALL(x) (x).begin(), (x.end()) #define MSET(a, x) memset(a, x, sizeof(a)) using namespace std; typedef unsigned long long ll; typedef pair<int, int> P; int read(){ int x=0,f=1;char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} return x*f; } const double pi=3.14159265358979323846264338327950288L; const double eps=1e-6; const int mod = 1e9 + 7; const ll INF = ~0LL; const int MAXN = 1005; const int xi[] = {0, 0, 1, -1}; const int yi[] = {1, -1, 0, 0}; ll prime[] = {1,2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53}; ll n, res1, res2; void dfs(ll now, ll cnt, ll limt, int pos){ if(now > n) return; if(pos > 15) return; if(cnt > res1) res1 = cnt, res2 = now; else if(cnt == res1 && res2 > now) res2 = now; for(ll i = 1; i <= limt; i++){ if((double)(now)*(prime[pos]) > double(n)) break; dfs(now *= prime[pos], cnt*(1+i), i, pos+1); } } int main() { //freopen("in.txt", "r", stdin); int t; scanf("%d", &t); while(t--){ res1 = 0, res2 = INF; cin >> n; dfs(1, 1, 60, 1); cout << res2 <<" " << res1 << endl; } return 0; }