题目链接

一道比较简单的莫比乌斯反演,不过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. JS-Array.prototype 中的方法的坑

    fill() 今天刷 HackerRank 的题遇到需要创建链表数组(一维数组的每一项是个链表)的题. 众所周知 JS 中的数组可以当链表用,我就用如下代码进行创建 let seqs = (new A ...

  2. UI自动化之三种等待

    UI自动化中常用三种等待 目录 1.强制等待 2.隐式等待 3.显示等待 1.强制等待 执行到某一条语句后,然后sleep(3),等待3秒后,才会继续执行后面的语句 2.隐式等待 隐式等待只需要声明一 ...

  3. UI自动化之8种基础定位

    UI自动化的核心在于定位 目录 1.8种基础定位方法 2.xpath定位 3.css定位 4.多组元素 1.8种基础定位方法 driver.find_element_by_id() #id定位 dri ...

  4. SpringBoot整合SpringMVC完成文件上传

    1.编写Controller /** * SPringBoot文件上传 */ //@Controller @RestController //表示该类下的方法的返回值会自动做json格式的转换 pub ...

  5. Java ——日期时间 日期时间相关类 随机数 定义类属性时建议使用引用数据类型

    本节重点思维导图 Date对象创建 两个构造函数: Date() ----使用当前日期和时间来初始化对象 Date(long millisec) -----接收一个参数,该参数是从1970年1月1日起 ...

  6. 【openstf】自己的云测平台——mac安装openstf

    openstf的github地址:https://github.com/openstf/stf 上图可以清晰看出openstf的使用场景和效果   openstf是一个web应用程序,用于远程调试智能 ...

  7. NOPI导入导出EXCEL

    一.简介 1. 什么是NPOI NPOI,顾名思义,就是POI的.NET版本.那POI又是什么呢?POI是一套用Java写成的库,能够帮助开发者在没有安装微软Office的情况下读写Office 97 ...

  8. SQL Puzzle

    1. 按条件分块取数据 有表A(CD),数据为 要求:当有CD为0的记录时,取得结果为0, 当表中没有CD=0的记录时,取得的结果为1,2,3(将CD<>0的记录都取出来) 可行SQL脚本 ...

  9. Eclipse查看jdk源码(Ctrl+左键)

    Window ->Preferences ->Java ->Installed JREs ->选中jdk ->Edit ->选中rt.jar ->source ...

  10. npm模块管理器

    npm模块管理器 地址: http://javascript.ruanyifeng.com/nodejs/npm.html#