SPOJ VLATTICE - Visible Lattice Points 【“小”大数加减】
一道比较简单的莫比乌斯反演,不过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 【“小”大数加减】的更多相关文章
- 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 ...
- [SPOJ VLATTICE]Visible Lattice Points 数论 莫比乌斯反演
7001. Visible Lattice Points Problem code: VLATTICE Consider a N*N*N lattice. One corner is at (0,0, ...
- SPOJ—VLATTICE Visible Lattice Points(莫比乌斯反演)
http://www.spoj.com/problems/VLATTICE/en/ 题意: 给一个长度为N的正方形,从(0,0,0)能看到多少个点. 思路:这道题其实和能量采集是差不多的,只不过从二维 ...
- 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 ...
- SPOJ VLATTICE Visible Lattice Points 莫比乌斯反演
这样的点分成三类 1 不含0,要求三个数的最大公约数为1 2 含一个0,两个非零数互质 3 含两个0,这样的数只有三个,可以讨论 针对 1情况 定义f[n]为所有满足三个数最大公约数为n的三元组数量 ...
- SPOJ VLATTICE Visible Lattice Points(莫比乌斯反演)题解
题意: 有一个\(n*n*n\)的三维直角坐标空间,问从\((0,0,0)\)看能看到几个点. 思路: 按题意研究一下就会发现题目所求为. \[(\sum_{i=1}^n\sum_{j=1}^n\su ...
- 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 ...
- spoj 7001. Visible Lattice Points GCD问题 莫比乌斯反演
SPOJ Problem Set (classical) 7001. Visible Lattice Points Problem code: VLATTICE Consider a N*N*N la ...
- Spoj 7001 Visible Lattice Points 莫比乌斯,分块
题目:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=37193 Visible Lattice Points Time L ...
随机推荐
- java将url里面的中文改成ASCII字符集 和 SCII字符集 改成 中文
package com.example.demo; import java.io.UnsupportedEncodingException; import java.net.URLDecoder; / ...
- windows 10中使用命令行关掉占用指定端口的程序
通过netstat -ano与findstr命令结合查询到带有9080端口的监听信息,图中最后一列为监听程序的PID 通过tasklist命令与findstr命令结合查询到指定PID对应的应用程序 使 ...
- day52—JavaScript拖拽事件的应用(自定义滚动条)
转行学开发,代码100天——2018-05-07 前面的记录里展示了JavaScript中鼠标拖拽功能,今天利用拖拽功能实现另一个应用场景——自定义滚动条(作为控制器)的用法. 常通过自定义滚动条控制 ...
- 002-localStorage和sessionStorage操作
一.概述 HTML5 提供了两种在客户端存储数据的新方法: localStorage - 没有时间限制的数据存储 一直存在除非用户手动清除缓存;是基于域的,任何该域下的所有页面都可访问localSto ...
- Delphi XE2 之 FireMonkey 入门(29) - 数据绑定: TBindingsList: 表达式的 Evaluate() 方法
Delphi XE2 之 FireMonkey 入门(29) - 数据绑定: TBindingsList: 表达式的 Evaluate() 方法 TBindingsList 中可能不止一个表达式, 通 ...
- python学习笔记(数据类型)
python数据类型: int 类型 float 小数类型 string 字符串 布尔类型 a = True b = False 1.列表,也称数组或list或array.它的表达方式通过下标或索引或 ...
- Git的资源地址
下载地址:https://git-scm.com/downloads 安装教程: https://baijiahao.baidu.com/s?id=1619087367741781687&wf ...
- 剑指offer--day01
1.1题目:二维数组中的查找:在一个二维数组中(每个一维数组的长度相同),每一行都按照从左到右递增的顺序排序,每一列都按照从上到下递增的顺序排序.请完成一个函数,输入这样的一个二维数组和一个整数,判断 ...
- 2019寒假作业二:PTA7-1币值转换
7-1 币值转换 (20 分) 输入一个整数(位数不超过9位)代表一个人民币值(单位为元),请转换成财务要求的大写中文格式.如23108元,转换后变成“贰万叁仟壹百零捌”元.为了简化输出,用小写英文字 ...
- stl应用
http://codeforces.com/problemset/problem/1154/E E. Two Teams time limit per test 2 seconds memory li ...