一个整数序列S的LCM(最小公倍数)是指最小的正整数X使得它是序列S中所有元素的倍数,那么LCM(S)=X。
例如,LCM(2)=2,LCM(4,6)=12,LCM(1,2,3,4,5)=60。
现在给定一个整数N(1<=N<=1000000),需要找到一个整数M,满足M>N,同时LCM(1,2,3,4,...,N-1,N) 整除 LCM(N+1,N+2,....,M-1,M),即LCM(N+1,N+2,....,M-1,M)是LCM(1,2,3,4,...,N-1,N) 的倍数.求最小的M值。
注意到M必然小于等于 2 * N。
计算LCM,我没想到分解质因数。同样道理,只要对N找出最大的质因数的那个次数。再乘2就会是答案。
#pragma warning(disable:4996) #include<iostream> #include<algorithm> #include<bitset> #include<tuple> #include<unordered_map> #include<fstream> #include<iomanip> #include<string> #include<cmath> #include<cstring> #include<vector> #include<map> #include<set> #include<list> #include<queue> #include<stack> #include<sstream> #include<cstdio> #include<ctime> #include<cstdlib> #define pb push_back #define INF 0x3f3f3f3f #define inf 0x7FFFFFFF #define moD 1000000003 #define pii pair<int,string> #define eps 1e-8 #define equals(a,b) (fabs(a-b)<eps) #define bug puts("bug") #define re register #define fi first #define se second typedef long long ll; typedef unsigned long long ull; const ll MOD = 1e9 + 7; const int maxn = 1e6 + 5; const double Inf = 10000.0; const double PI = acos(-1.0); using namespace std; int prime[maxn]; int vis[maxn]; int euler_sieve(int n) { int cnt = 0; for (int i = 2; i <= n; i++) { if (!vis[i]) prime[cnt++] = i; for (int j = 0; j < cnt; j++) { if (i * prime[j] > n) break; vis[i * prime[j]] = 1; if (i % prime[j] == 0) break; } } return cnt; } int main() { euler_sieve(maxn - 3); int T; scanf("%d", &T); while (T--) { ll n; scanf("%lld", &n); if (n == 1) { puts("2"); continue; } ll Max = -1; for (int i = 2; i <= n; i++) { if (!vis[i]) { ll tmp = i; while (tmp * i <= n) tmp *= i; Max = max(Max, tmp); } } printf("%lld ", Max << 1); } }