题目描述
t次询问,每次给你一个数n,求在[1,n]内约数个数最多的数的约数个数
输入描述:
第一行一个正整数t
之后t行,每行一个正整数n
输出描述:
输出t行,每行一个整数,表示答案
输入
5 13 9 1 13 16
输出
6 4 1 6 6
备注:
对于100%的数据,t <= 500 , 1 <= n <= 1000000000000000000
#include<bits/stdc++.h> using namespace std; const int N = 1e5 + 7; typedef long long LL; const LL M = 1000000000000000000; const LL p[17] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59}; int prime[N]; LL ans, n; void getPrime() { memset(prime, 0, sizeof(prime)); for (int i = 2; i < N; i++) { if (!prime[i]) prime[++prime[0]] = i; for (int j = 1; j <= prime[0] && prime[j] * i < N; j++) { prime[prime[j] * i] = 1; if (i % prime[j] == 0) break; } } } inline LL read() { #define isDigit(ch) (ch >= '0' && ch <= '9') char ch = getchar(); LL x = 0, f = 1; while (!isDigit(ch)) { if (ch == '-') f = -1; ch = getchar(); } while (isDigit(ch)) { x = x * 10 + ch - '0'; ch = getchar(); } return x * f; } void dfs(int ps, LL cur, LL c, int pre) { if (ps > 17) return; ans = max(ans, c); LL now = cur; for (int i = 1; i <= pre && n / p[ps] >= now; i++) { now *= p[ps]; dfs(ps + 1, now, c * (i + 1), i); } } int main() { int t; cin >> t; while (t--) { ans = 0; n = read(); dfs(0, 1, 1, 64); cout << ans << endl; } return 0; }
原文链接: https://www.cnblogs.com/HighLights/p/13321235.html
欢迎关注
微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍;
也有高质量的技术群,里面有嵌入式、搜广推等BAT大佬
原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/367096
非原创文章文中已经注明原地址,如有侵权,联系删除
关注公众号【高性能架构探索】,第一时间获取最新文章
转载文章受原作者版权保护。转载请注明原作者出处!