LCM from 1 to n

Connection: https://www.cnblogs.com/outerform/p/5921945.html

If n + 1 is not a perfect square prime number, the prime factor can be decomposed into p1 ^ a1 * p2 ^ a2 * ...... pn ^ an, for each pi ^ ai, apparently <n, and the pairwise nature, so p1 ^ a1 * p2 ^ a2 * ...... pn ^ an | L (n), so that n + 1 | L (n), L (n +1) = L (n)

If n + 1 is a perfect square prime, then n + 1 = p ^ k, p ^ k does not divide 1 ... .n, p ^ k does not divide L (n), as p ^ (k-1) | L ( n), so that p ^ (k-1) * p | L (n) * p, so that L (n + 1) = L (n) * p.

Sieving compressed to save space bit map when evaluated prime.

After pre-treatment and then a prime plot a prefix, then small to large power of enumeration and look through half of the largest prime number is the number of times this power, every answer and to take on this prefix.

unsigned int automatic modulo 2 ^ 32

#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<queue>
#include<set>
#include<map>
#include<vector>
#include<bitset>

#define int unsigned int
#define inf 0x3f3f3f3f
#define mem(a,b) memset(a,b,sizeof(a))
#define ll long long
#define sd(x) scanf("%d",&(x))
#define sl(x) scanf("%lld",&(x))
#define slf(x) scanf("%lf",&(x))
#define scs(s) scanf("%s",s)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=a;i>=b;i--)
#define lowbit(x) x&(-x)
#define ls now<<1
#define rs now<<1|1
#define lson l,mid,ls
#define rson mid+1,r,rs

using namespace std;

const int maxn=6e6+10;

bitset<100000010> is_prime;
 int ans,sum[maxn];
 int prime[maxn],tot=0;

void oula()
{
    is_prime[1]=is_prime[0]=1;
    rep(i,2,1e8)
    {
        if(!is_prime[i]) prime[++tot]=i;
        for(int j=1;j<=tot&&i*prime[j]<=1e8;j++)
        {
            is_prime[i*prime[j]]=1;
            if(i%prime[j]==0) break;
        }
    }
}
#undef int
int main()
{
#define int unsigned int
    oula();
    sum[0]=1;
    rep(i,1,tot)
        sum[i]=sum[i-1]*prime[i];
    int t,n;
    scanf("%u",&t);
    for(int mun=1;mun<=t;mun++)
    {
        scanf("%u",&n);
        ans=1;
        int cnt=1;
        while(1)
        {
            int m=(int)pow(n+0.9,1.0/cnt);
            if(m<2) break;
            int i=lower_bound(prime+1,prime+1+tot,m)-prime;
            if(prime[i]!=m)i--;
            ans*=sum[i];
            cnt++;
        }
        printf("Case %u: %u\n",mun,ans);
    }
    return 0;
}

 

Guess you like

Origin www.cnblogs.com/minun/p/11347172.html