light oj 1007 Mathematically Hard (Eulerian function)

Title address: light oj 1007
first issued Euler function.
Important properties of the Euler function:
Let a be a prime factor of N. If (N % a == 0 && (N / a) % a == 0) then E(N)=E(N / a) * a; if (N % a == 0 && (N / a) % a != 0) then: E(N) = E(N / a) * (a - 1)
for this problem. First card MLE. .

Only one array can be opened. . So the prefix sum is also stored in the Euler array.

Then stuck long long.

. Use unsigned long long .

.
The code is as follows:

#include <iostream>
#include <string.h>
#include <math.h>
#include <queue>
#include <algorithm>
#include <stdlib.h>
#include <map>
#include <set>
#include <stdio.h>
#include <time.h>
using namespace std;
#define LL long long
#define pi acos(-1.0)
#pragma comment(linker, "/STACK:1024000000")
const int mod=9901;
const int INF=0x3f3f3f3f;
const double eqs=1e-9;
const int MAXN=5000000+10;
unsigned LL euler[MAXN];
void init()
{
        int i, j, max1=5000000;
        for(i=2;i<=max1;i++){
                euler[i]=i;
        }
        for(i=2;i<=max1;i++){
                if(euler[i]!=i) continue ;
                for(j=i;j<=max1;j+=i){
                        euler[j]=euler[j]/i*(i-1);
                }
        }
        for(i=2;i<=max1;i++){
                euler[i]=euler[i-1]+euler[i]*euler[i];
        }
}
int main()
{
        int t, l, r, icase=0;
        scanf("%d",&t);
        init();
        while(t--){
                scanf("%d%d",&l,&r);
                printf("Case %d: %llu\n",++icase,euler[r]-euler[l-1]);
        }
        return 0;
}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324851981&siteId=291194637