ACM-ICPC 2018 南京赛区网络预赛 J.sum(线性筛)*

题目链接:https://nanti.jisuanke.com/t/A1956
题面:

A square-free integer is an integer which is indivisible by any square number except 11. For example, 6 = 2 \cdot 3,6=2⋅3 is square-free, but 12 = 2^2 \cdot 312=2

⋅3 is not, because 2^22
2
is a square number. Some integers could be decomposed into product of two square-free integers, there may be more than one decomposition ways. For example, 6 = 1\cdot 6=6 \cdot 1=2\cdot 3=3\cdot 2, n=ab6=1⋅6=6⋅1=2⋅3=3⋅2,n=ab and n=ban=ba are considered different if a \not = ba


=b. f(n)f(n) is the number of decomposition ways that n=abn=ab such that aa and bb are square-free integers. The problem is calculating ∑ i = 1 n f ( i ) . \sum_{i = 1}^nf(i). i=1nf(i).

Input
The first line contains an integer T(T\le 20)T(T≤20), denoting the number of test cases.

For each test case, there first line has a integer n(n \le 2\cdot 10^7)n(n≤2⋅10
7
).

Output
For each test case, print the answer \sum_{i = 1}^n f(i)∑
i=1
n

f(i).

Hint
∑ i = 1 8 f ( i ) = f ( 1 ) + ⋯ + f ( 8 ) = 1 + 2 + 2 + 1 + 2 + 4 + 2 + 0 = 14. \sum_{i = 1}^8 f(i)=f(1)+ \cdots +f(8) \\ =1+2+2+1+2+4+2+0=14. i=18f(i)=f(1)++f(8)=1+2+2+1+2+4+2+0=14.

样例输入 复制
2
5
8
样例输出 复制
8
14
题目来源
ACM-ICPC 2018 南京赛区网络预赛


非线性筛做法(这个做法应该不是线性筛)

先预处理,将不含平方因子的数放在f数组中,f[1…i]表示前i个不含平方因子的数
同时预处理sum[i],sum[i]表示正整数i前面不含平方因子的个数(包括i本身)
S ( n ) S(n) S(n)为题目所求,那么S(n)就等于所有的a*b(a,b不含平方因子且a*b<=n)的情况数。
以n=20举例,所有的情况如下:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值