SQFREE - Square-free integers

求n以内,约数中不包含任意一个平方数的个数,\(n≤10^{14}\)。

显然为约数计数问题,于是想办法转换为代数问题,不难列出

\[ans=\sum_{i=1}^n\mu^2(i)\]

没有gcd,不好反演,考虑容斥,则有

\[ans=\sum_{i=1}^{\sqrt{n}}\mu(i)[n/i^2]\]

以此即可解决问题,时间复杂度\(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();
}

转载于:https://www.cnblogs.com/a1b3c7d9/p/10884606.html

SQFREE - Square-free integers相关推荐

  1. sqrt numpy_NumPy sqrt()–矩阵元素的平方根

    sqrt numpy Python NumPy module is used to work with multidimensional arrays and matrix manipulations ...

  2. 《SICP》习题第3章(施工中)

    本人做的SICP习题第3章,如有错误请指正,用的解释器是Racket 练习3.1 ;; 累加器 (define (make-accumulator initial)(lambda (x)(let (( ...

  3. 5kyu Square sums (simple)

    5kyu Square sums (simple) 题目背景: Task Write function square_sums_row (or squareSumsRow/SquareSumsRow ...

  4. 北邮OJ 2016 网预-Square Coins

    时间限制 1000 ms 内存限制 65536 KB 题目描述 Artoria, also known as Saber-chan, was born into a time of chaos and ...

  5. Minimal Square CodeForces - 1360A(简单思维和图形判断)

    题意: 给你两个大小一样的,边长为a,b的矩形将其放入一个正方形里,问怎样放可以使正方形面积最小(要求正方形边和矩形边平行) 题目: Find the minimum area of a square ...

  6. 【HDU - 1518】Square (经典的dfs + 剪枝)

    题干: Given a set of sticks of various lengths, is it possible to join them end-to-end to form a squar ...

  7. cf369 B Chris and Magic Square

    B. Chris and Magic Square time limit per test2 seconds memory limit per test256 megabytes inputstand ...

  8. lintcode: Check Sum of Square Numbers

    Check Sum of Square Numbers Given a integer c, your task is to decide whether there're two integers ...

  9. leetcode 1925. Count Square Sum Triples(python)

    描述 A square triple (a,b,c) is a triple where a, b, and c are integers and a^2 + b^2 = c^2. Given an ...

最新文章

  1. 如何理解:先减1后取反和先取反后加1得到的结果是一样的,故仍可采用取反加1的方法,即对于机器数为负数,则有[X]原=[[X]补]补。
  2. 什么是BusyBox?
  3. CF914G Sum the Fibonacci(FWT模板+子集卷积)
  4. L1-068 调和平均 (10 分)-PAT 团体程序设计天梯赛 GPLT
  5. Modern CMake 翻译 2.1 变量和缓存
  6. iOS 提交app到iTunes Connect,显示构建版本“+”号的小技巧/ 选择版本提交 无“+”号 问题/Xcode 上传成功但iTunes 不显示上传的版本的问题
  7. 易筋SpringBoot 2.1 | 第一篇:构建第一个SpringBoot工程
  8. CSS实现半透明边框
  9. 解决Sublime提示 Sublime Text Error while loading PyV8 binary:exit code 1 Try to manually install Pyv8 fo
  10. volte的sip信令流程_VOLTE-SIP完整信令解析
  11. 新闻发布系统(java实现)+论文
  12. 微信公众号开发-自定义菜单
  13. php——三篇夯实根基第三篇
  14. 计算机毕业设计(附源码)python医院人事及科室病区管理
  15. vue导出js中的函数_js中的函数
  16. 电脑计算机找不到指定的程序,光驱双击显示找不到应用程序。怎么办?
  17. mysql 查询近三个月数据
  18. 深度学习课程大纲_MIT深度学习基础-2019视频课程分享
  19. 50款巧夺天工的PSD按钮素材
  20. CentOS radius 安装

热门文章

  1. 第 19 章 迭代器模式
  2. 用elastic stack来分析下你的redis slowlog
  3. pythonnumpy详解_Python精讲Numpy基础,大牛笔记详细解释
  4. php中时间怎么自动实现的,php怎么实现服务器时间自动跳动
  5. python实现食品推荐_Python分析亚马逊赞不绝口食物评论
  6. 通俗讲解c语言指针的作用,C语言指针讲解(史上最通俗最全面最经典)
  7. linux写语句自动执行一次,Linux系统下自动执行指定任务 cron
  8. java画方块_[求助]用Swing就画一个方块代码出错了
  9. 菜单栏底部线条切换效果
  10. 嘉兴市计算机技工学校,嘉兴市高级技工学校2021年招生简章