题目链接

一道比较简单的莫比乌斯反演,不过ans会爆long long,我是用结构体来存结果的,结构体中两个LL型变量分别存大于1e17和小于1e17的部分

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;

const int maxn=1e6;

];
];
];

void init()
{
    mu[]=;
    ;
    ;i<=maxn;i++)
    {
        if(!check[i])
        {
            prime[tot++]=i;
            mu[i]=-;
        }
        ;j<tot;j++)
        {
            if(i*prime[j]>maxn) break;
            check[i*prime[j]]=true;
            )
            {
                mu[i*prime[j]]=;
                break;
            }
            else
            {
                mu[i*prime[j]]=-mu[i];
            }
        }
    }
}

LL n;

const LL mod=1e17;
struct node
{
    LL a,b;
    node(LL a_=,LL b_=)
    {
        a=a_,b=b_;
    }
    void print()
    {
        if(a)    printf("%lld%017lld\n",a,b);
        else printf("%lld\n",b);
    }
};

node add(node x,LL y)
{
    )
    {
        LL t1=(x.b+y)/mod;
        LL t2=(x.b+y)%mod;
        x.a+=t1,x.b=t2;
        return x;
    }
    else
    {
        LL t1=(x.b+y)/mod;
        LL t2=(x.b+y)%mod;
        &&t2<) t2+=mod,t1--;
        x.a+=t1,x.b=t2;
        return x;
    }
}

int main()
{
    init();
    int T;
    node t;
    LL x;
    scanf("%d",&T);
    while(T--)
    {
        scanf("%lld",&n);
        node ans;
        ;i<=n;i++)
            ans=add(ans,mu[i]*(n/i)*(n/i)*(n/i));
        ;i<=n;i++)
            ans=add(ans,mu[i]*(n/i)*(n/i)*);
        ans=add(ans,);
        ans.print();
    }
}

SPOJ VLATTICE - Visible Lattice Points 【“小”大数加减】的更多相关文章

  1. SPOJ VLATTICE Visible Lattice Points (莫比乌斯反演基础题)

    Visible Lattice Points Consider a N*N*N lattice. One corner is at (0,0,0) and the opposite one is at ...

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

    7001. Visible Lattice Points Problem code: VLATTICE Consider a N*N*N lattice. One corner is at (0,0, ...

  3. SPOJ—VLATTICE Visible Lattice Points(莫比乌斯反演)

    http://www.spoj.com/problems/VLATTICE/en/ 题意: 给一个长度为N的正方形,从(0,0,0)能看到多少个点. 思路:这道题其实和能量采集是差不多的,只不过从二维 ...

  4. SPOJ VLATTICE Visible Lattice Points 莫比乌斯反演 难度:3

    http://www.spoj.com/problems/VLATTICE/ 明显,当gcd(x,y,z)=k,k!=1时,(x,y,z)被(x/k,y/k,z/k)遮挡,所以这道题要求的是gcd(x ...

  5. SPOJ VLATTICE Visible Lattice Points 莫比乌斯反演

    这样的点分成三类 1 不含0,要求三个数的最大公约数为1 2 含一个0,两个非零数互质 3 含两个0,这样的数只有三个,可以讨论 针对 1情况 定义f[n]为所有满足三个数最大公约数为n的三元组数量 ...

  6. SPOJ VLATTICE Visible Lattice Points(莫比乌斯反演)题解

    题意: 有一个\(n*n*n\)的三维直角坐标空间,问从\((0,0,0)\)看能看到几个点. 思路: 按题意研究一下就会发现题目所求为. \[(\sum_{i=1}^n\sum_{j=1}^n\su ...

  7. 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 th ...

  8. spoj 7001. Visible Lattice Points GCD问题 莫比乌斯反演

    SPOJ Problem Set (classical) 7001. Visible Lattice Points Problem code: VLATTICE Consider a N*N*N la ...

  9. Spoj 7001 Visible Lattice Points 莫比乌斯,分块

    题目:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=37193   Visible Lattice Points Time L ...

随机推荐

  1. native-echarts 组件封装

    CommunalChart.js /** * 封装 图表组件 */ import React, { Component } from 'react'; import { StyleSheet, Tex ...

  2. pepflashplayer32_25_0_0_127.dll: 0x59952C6D is not a valid instance ID.

    pepflashplayer32_25_0_0_127.dll: 0x59952C6D is not a valid instance ID. . 点进去是提示doctype错误 暂时没有解决---- ...

  3. SeaJS基本开发原则

    SeaJS基本开发原则在讨论SeaJS的具体使用前,先介绍一下SeaJS的模块化理念和开发原则.使用SeaJS开发JavaScript的基本原则就是:一切皆为模块.引入SeaJS后,编写JavaScr ...

  4. easyui表格适应bootstrap

    .panel1 { overflow: hidden; text-align: left; margin:; border:; -moz-border-radius: 0 0 0 0; -webkit ...

  5. Ajax初探

    一.AJAX准备知识:JSON 1.stringify与parse方法 2.和XML的比较 二.AJAX简介 AJAX常见应用情景 AJAX的优缺点 优点: 三.jQuery实现的AJAX $.aja ...

  6. 用Vue来实现音乐播放器(10):Scroll组件的抽象和应用

    了解better-scroll什么时候是需要refresh计算的??通常我们遇到的better-scroll不能滚动的问题的根源是什么??better-scroll的渲染原理是:根据初始化的时机  或 ...

  7. python字典小知识

    字典的小知识dic = {"name": "tom", "age": 23, "price": 110}# 01:提取键 ...

  8. 1.k8s.资源清单

    #k8s常用资源 工作负载:Pod,rs(ReplicasSet),deploy(Deployment),sts(StatefulSet),ds(DaemonSet),Job,Cronjob 服务发现 ...

  9. 修改属性item1(1变化)

    给imgList1,7,12,16添加数据 数据层data:{imgList1:[],imgList7:[],imgList12:[],imgList16:[],} 处理层let _this=this ...

  10. debian下重装mysql

    mysql总是报错,说sock文件不存在,网上若干方法,更改权限,更改配置文件,结果还是不能正常生成.sock文件.没办法,删除,重新安装. 完全删除: 删除 mysqlsudo apt-get au ...