Loj 6165. A water problem (linear sieve)

Source: Internet
Author: User
Title Description Transmission Door

The main idea is to find the smallest integer that can divide [1,n] into 100000007. Solving

is actually to ask for the least common multiple in [1,n], least common multiple equals ∏pimax (QI) \prod Pi^{max (QI)}
That is, the product of the maximum power of all the mass factors.
Just beginning to think that the 108 10^8 linear sieve can not be, but the loj of the evaluation machine is faster, all directly do the code

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define N 100000003
#define MX 10000
#define LL long long 
#define P 100000007
using namespace std;
bool Pd[n];
int n,prime[6000000];
int main ()
    scanf ("%d", &n); LL Ans=1;
    for (int i=2;i<=n;i++) {
        if (!pd[i]) {
            LL t=i;
            while (t* (LL) i<=n) t*=i;
        for (int j=1;j<=prime[0];j++) {
            int k=i*prime[j];
            if (k>n) break;
            if (i%prime[j]==0) break;
    printf ("%lld\n", ans);

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.