Hdu 2824 The Euler function (Euler function)

Source: Internet
Author: User

If the table is typed, the memory will be exceeded. I think of a way to solve this problem. When the data given in the question is 3000000, I divide 3 million into 300 pieces of data, and store all pieces of data. When calculating the data, I first calculate the total data between x and y, then calculate the scattered data.

The idea is good, but why can't it work? In addition, we can see that the last two groups of data are stuck.

I am confused.

The comments in the Code are my previous code. In the end, this question turned out to have no sense of violence.

 

#include<stdio.h>#include<string.h>#define N 3000005int a[N];int b[N];__int64 c[310];int main(){    int i,j;    for(i=2;i<N;i++)        a[i]=i;    for(i=2;i<N;i++)    {        if(b[i]==1)            continue;        a[i]=i-1;        for(j=i+i;j<N;j=j+i)        {            b[j]=1;            a[j]=a[j]/i*(i-1);        }    }    a[1]=a[0]=0;    c[1]=0;    __int64 temp;    c[0]=0;    j=1;    temp=0;    for(i=2;i<N;i++)    {        temp+=a[i];        if(i%10000==0)            c[j++]=temp;    }    int x,y;    while(scanf("%d%d",&x,&y)!=EOF)    {        __int64 sum=0;        /*        int x1,y1;        x1=x/10000;        y1=y/10000;        if(x1==y1)        {            for(i=x;i<=y;i++)                sum+=a[i];        }        else        {            sum+=c[y1]-c[x1];            for(i=x1*10000+1;i<x;i++)                sum-=a[i];            for(i=y1*10000+1;i<=y;i++)                sum+=a[i];        }        */        for(i=x;i<=y;i++)            sum+=a[i];        printf("%I64d\n",sum);    }    return 0;}

 

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.