Visible Lattice Points SPOJ - VLATTICE 三维+莫比乌斯反演

#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn=1e7+10;
int vis[maxn];
int mu[maxn];
int prime[maxn];
int tot=0;
int sum1[maxn];
int sum2[maxn];
void get_mu()
{
    mu[1]=1; vis[1]=1;
    for(int i=2;i<maxn;i++)
    {
        if(!vis[i]) {mu[i]=-1; prime[++tot]=i; }
        for(int j=1;j<=tot && i*prime[j]<maxn;j++)
        {
            vis[i*prime[j]]=1;
            if(i%prime[j]==0) break;
            mu[i*prime[j]]=-mu[i];
        }
    }
    for(int i=1;i<maxn;i++)
        sum2[i]=sum2[i-1]+mu[i];
}
int main()
{
    get_mu();
    int T; cin>>T;
    while(T--)
    {
        int n; cin>>n;
        ll ans=0;
        for(int l=1,r;l<=n;l=r+1)
        {
            r=n/(n/l);
            ans+=(sum2[r]-sum2[l-1])*1ll*(n/l)*(n/l)*(n/l);
            ans+=(sum2[r]-sum2[l-1])*1ll*(n/l)*(n/l)*3;
        }
        cout<<ans+3<<endl;
    }
}

原文地址:https://www.cnblogs.com/Andromeda-Galaxy/p/10704583.html

时间: 2024-10-17 08:47:45

Visible Lattice Points SPOJ - VLATTICE 三维+莫比乌斯反演的相关文章

A - Visible Lattice Points SPOJ - VLATTICE 容斥原理/莫比乌斯反演

Consider a N*N*N lattice. One corner is at (0,0,0) and the opposite one is at (N,N,N). How many lattice points are visible from corner at (0,0,0) ? A point X is visible from point Y iff no other lattice point lies on the segment joining X and Y. Inpu

Visible Lattice Points(spoj7001+初探莫比乌斯)gcd(a,b,c)=1 经典

VLATTICE - Visible Lattice Points no tags Consider a N*N*N lattice. One corner is at (0,0,0) and the opposite one is at (N,N,N). How many lattice points are visible from corner at (0,0,0) ? A point X is visible from point Y iff no other lattice point

[SPOJ VLATTICE]Visible Lattice Points 数论 莫比乌斯反演

7001. Visible Lattice Points Problem code: VLATTICE Consider a N*N*N lattice. One corner is at (0,0,0) and the opposite one is at (N,N,N). How many lattice points are visible from corner at (0,0,0) ? A point X is visible from point Y iff no other lat

spoj 7001 Visible Lattice Points莫比乌斯反演

Visible Lattice Points Time Limit:7000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Submit Status Description Consider a N*N*N lattice. One corner is at (0,0,0) and the opposite one is at (N,N,N). How many lattice points are visible from co

SPOJ1007 VLATTICE - Visible Lattice Points

VLATTICE - Visible Lattice Points no tags Consider a N*N*N lattice. One corner is at (0,0,0) and the opposite one is at (N,N,N). How many lattice points are visible from corner at (0,0,0) ? A point X is visible from point Y iff no other lattice point

数论 - 欧拉函数的运用 --- poj 3090 : Visible Lattice Points

Visible Lattice Points Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 5636   Accepted: 3317 Description A lattice point (x, y) in the first quadrant (x and y are integers greater than or equal to 0), other than the origin, is visible fr

POJ 3090 Visible Lattice Points 欧拉函数

链接:http://poj.org/problem?id=3090 题意:在坐标系中,从横纵坐标 0 ≤ x, y ≤ N中的点中选择点,并且这些点与(0,0)的连点不经过其他的点. 思路:显而易见,x与y只有互质的情况下才会发生(0,0)与(x,y)交点不经过其他的点的情况,对于x,y等于N时,可以选择的点均为小于等于N并且与N互质的数,共Euler(N)个,并且不重叠.所以可以得到递推公式aa[i]=aa[i]+2*Euler(N). 代码: #include <iostream> #in

POJ 3090 Visible Lattice Points

Description A lattice point (x, y) in the first quadrant (x and y are integers greater than or equal to 0), other than the origin, is visible from the origin if the line from (0, 0) to (x, y) does not pass through any other lattice point. For example

POJ 3090 Visible Lattice Points 布雷级数

Visible Lattice Points Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 5779   Accepted: 3409 Description A lattice point (x, y) in the first quadrant (x and y are integers greater than or equal to 0), other than the origin, is visible fr