SQFREE - Square-free integers
求n以内,约数中不包含任意一个平方数的个数,\(n≤10^{14}\)。
解
显然为约数计数问题,于是想办法转换为代数问题,不难列出
\]
没有gcd,不好反演,考虑容斥,则有
\]
以此即可解决问题,时间复杂度\(O(\sqrt{n})\)。
参考代码:
#include <iostream>
#include <cstdio>
#include <cmath>
#define il inline
#define ri register
#define ll long long
#define Size 10000000
using namespace std;
bool check[Size+1];
int prime[1000000],pt,mu[Size+1];
template<class free>
il void read(free&);
il void prepare(int);
int main(){
int lsy;read(lsy);
ll n,i,j,ans;prepare(Size);
while(lsy--){
read(n),ans&=0;
for(i=1;i*i<=n;i=j+1)
j=sqrt(n/(n/(i*i))),
ans+=(mu[j]-mu[i-1])*(n/(i*i));
printf("%lld\n",ans);
}
return 0;
}
il void prepare(int n){
ri int i,j;mu[1]=1;
for(i=2;i<=n;++i){
if(!check[i])prime[++pt]=i,mu[i]=-1;
for(j=1;j<=pt&&prime[j]*i<=n;++j){
check[i*prime[j]]|=true;
if(!(i%prime[j]))break;
mu[i*prime[j]]=-mu[i];
}
}for(i=1;i<=n;++i)mu[i]+=mu[i-1];
}
template<class free>
il void read(free &x){
x&=0;ri char c;while(c=getchar(),c<'0'||c>'9');
while(c>='0'&&c<='9')x=(x<<1)+(x<<3)+(c^48),c=getchar();
}
SQFREE - Square-free integers的更多相关文章
- 【转】 Anatomy of Channels in Go - Concurrency in Go
原文:https://medium.com/rungo/anatomy-of-channels-in-go-concurrency-in-go-1ec336086adb --------------- ...
- Codeforces 715A. Plus and Square Root[数学构造]
A. Plus and Square Root time limit per test 2 seconds memory limit per test 256 megabytes input stan ...
- HDU1518 Square(DFS,剪枝是关键呀)
Square Time Limit : 10000/5000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other) Total Submi ...
- [Educational Codeforces Round 16]C. Magic Odd Square
[Educational Codeforces Round 16]C. Magic Odd Square 试题描述 Find an n × n matrix with different number ...
- HDU1518 Square(DFS)
Square Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Su ...
- HDOJ 1518 Square
Square Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Sub ...
- Codeforces 612E - Square Root of Permutation
E. Square Root of Permutation A permutation of length n is an array containing each integer from 1 t ...
- Square
Square TimeLimit: 1 Second MemoryLimit: 32 Megabyte Totalsubmit: 1638 Accepted: 440 Description ...
- HDU-1518 Square(DFS)
Square Time Limit : 10000/5000ms (Java/Other) Memory Limit : 65536/32768K (Java/Other) Total Submi ...
随机推荐
- .Net Core 部署之一 《CentOS 从GitHub/Gitee 等源代码网站部署Web网站》
先看下楼主从某阿打折购买的渣渣服务器 lsb_release -a 一.安装dotnet-SDK 注册微软的服务 sudo rpm -Uvh https://packages.microsoft.co ...
- jQuery 基本选择器
1 基本选择器 $(‘#id属性值’) ----------->document.getElementById() $(‘tag标签名称’)----------->document.ge ...
- 10、 导出python脚本进行数据驱动的接口测试
postman自带脚本导出功能,对于代码小白来说,可以不错的学习代码级接口测试 第一步:输入接口地址,点击send 第二步:点击code,导出脚本文件,为python脚本 第三步:安装python3以 ...
- 函数的属性和方法, apply和call的区别及bind的使用
==>我的新博客中 http://www.suanliutudousi.com/2017/08/27/%E5%87%BD%E6%95%B0%E7%9A%84%E5%B1%9E%E6%80%A7% ...
- Python3 多进程编程 - 学习笔记
Python3 多进程编程(Multiprocess programming) 为什么使用多进程 具体用法 Python多线程的通信 进程对列Queue 生产者消费者问题 JoinableQueue ...
- Activiti学习笔记6 — 变量与历史记录
一. 变量的使用 1.创建流程引擎对象 private ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine(); ...
- 2018-10-8-Win10-使用-GHO-安装出现-UWP-软件打开闪退-应用商店无法安装软件
title author date CreateTime categories Win10 使用 GHO 安装出现 UWP 软件打开闪退 应用商店无法安装软件 lindexi 2018-10-8 18 ...
- Leetcode274.H-IndexH指数
原题的中文翻译不是很好,所以给出英文版. Given an array of citations (each citation is a non-negative integer) of a rese ...
- Android开发 retrofit入门讲解 (RxJava模式)
前言 retrofit除了正常使用以外,还支持RxJava的模式来使用,此篇博客讲解如何使用RxJava模式下的retrofit 依赖 implementation 'com.squareup.ret ...
- VS2010-MFC(工具栏:工具栏的创建、停靠与使用)
转自:http://www.jizhuomi.com/software/217.html 上一节教程讲了工具栏资源及CToolBar类,本节继续讲解工具栏的相关知识,主要内容包括工具栏的创建.停靠与使 ...