J. Sum

  • 26.87%
  • 1000ms
  • 512000K
 

A square-free integer is an integer which is indivisible by any square number except 11. For example, 6 = 2 \cdot 36=2⋅3 is square-free, but 12 = 2^2 \cdot 312=22⋅3 is not, because 2^222 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 \sum_{i = 1}^nf(i)∑i=1n​f(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⋅107).

Output

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

Hint

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

样例输入复制

2
5
8

样例输出复制

8
14

题目来源

ACM-ICPC 2018 南京赛区网络预赛

题意很好理解,就是求1-n中没有平方因数的数的个数。首先预处理出来,然后就直接输出就可以了。

类似欧拉函数筛素数,在筛素数的时候把平方因数筛掉就可以了。

代码:

 //J-筛无平方因数的数
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<deque>
#include<iomanip>
#include<list>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<vector>
using namespace std;
typedef long long ll; const double PI=acos(-1.0);
const double eps=1e-;
const ll mod=1e9+;
const int inf=0x3f3f3f3f;
const int maxn=2e7+;
const int maxm=+;
#define ios ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); bool is_prime[maxn];
int prime[maxn];
ll f[maxn],ans[maxn];
int h; void init(int n)
{
f[]=;
for(int i=;i<n;i++){
if(!is_prime[i]){
prime[++h]=i;
f[i]=;
}
for(int j=;j<=h&&i*prime[j]<n;j++){
is_prime[i*prime[j]]=;
if(i%prime[j]==){
if(i%(prime[j]*prime[j])==)
f[i*prime[j]]=;
else
f[i*prime[j]]=f[i]/;
break;
}
else{
f[i*prime[j]]=f[i]*;
}
}
}
for(int i=;i<maxn;i++)
ans[i]=ans[i-]+f[i];
} int main()
{
h=;
init(maxn);
int t;
scanf("%d",&t);
while(t--){
int n;
scanf("%d",&n);
printf("%lld\n",ans[n]);
}
return ;
}

溜了。。。

计蒜客 30999.Sum-筛无平方因数的数 (ACM-ICPC 2018 南京赛区网络预赛 J)的更多相关文章

  1. 计蒜客 31458.Features Track-滚动数组+STL(map)连续计数 (ACM-ICPC 2018 徐州赛区网络预赛 F)

    F. Features Track Morgana is learning computer vision, and he likes cats, too. One day he wants to f ...

  2. ACM-ICPC 2018 南京赛区网络预赛 J.sum

    A square-free integer is an integer which is indivisible by any square number except 11. For example ...

  3. ACM-ICPC 2018 南京赛区网络预赛 J sum (找一个数拆成两个无平方因子的组合数)

    题目大意:就是找一个数拆成两个无平方因子的组合数,然后求个前缀和  ; 分析:运用筛法的思想 ,  因为有序对是由两个合法的数字组成的,所以只要保证第一个数合法,第二个数也合法就行,找出合法的第二个数 ...

  4. ACM-ICPC 2018 南京赛区网络预赛 J.sum(欧拉筛)

    题目来源:https://nanti.jisuanke.com/t/A1956 题意:找一个数拆成无平方因子的组合数,然后求前缀和. 解题思路:我们可以把某个数分解质因数,如果某个数可以分解出三个相同 ...

  5. ACM-ICPC 2018 南京赛区网络预赛 J题Sum(线性筛素数)

    题目链接:https://nanti.jisuanke.com/t/30999 参考自博客:https://kuangbin.github.io/2018/09/01/2018-ACM-ICPC-Na ...

  6. 线性素数筛 ACM-ICPC 2018 南京赛区网络预赛 J Sum

    https://www.jisuanke.com/contest/1555?view=challenges 题意: 题解:写完都没发现是个积性函数233 想法就是对x分解质因数,f(x)就是2^k,其 ...

  7. 【ACM-ICPC 2018 南京赛区网络预赛 J】Sum

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 线性筛求出每个数的最小质因子x for 从1-n 对于i,它的最小质因子为x 考虑i=ab 如果i能被x^3整除 那么这x怎么分配给 ...

  8. ACM-ICPC 2018 南京赛区网络预赛 J Sum (思维+打表)

    https://nanti.jisuanke.com/t/30999 题意 f(i)表示i能拆分成两个数的乘积,且要求这两个数中各自都没有出现超过1次的质因子的方案数.每次给出n,求∑(n,i=1)f ...

  9. ACM-ICPC 2018 南京赛区网络预赛 - J. Sum (找规律+打表)

    题意:\(f(i):i\)能拆分成两个数的乘积,且要求这两个数中各自都没有出现超过1次的质因子.每次给出n,求\(\sum_{i=1}^{n}f(i)\) 分析:\(1 \le n \le 2e7\) ...

随机推荐

  1. [剑指Offer] 14.链表中倒数第k个结点

    [思路]利用两个相隔为k-1个结点的指针进行遍历,当后一个指针移到末尾时,前一个指针就是要求的结点. /* struct ListNode { int val; struct ListNode *ne ...

  2. jQuery下拉列表二级联动插件

    jQuery下拉列表二级联动插件的视图代码: <!doctype html> <html lang="en"> <head> <meta ...

  3. [CF107D]Crime Management

    题目大意:有一种长度为$n(n\leqslant 10^{18})$的字符串,给定$m(m\leqslant10^3)$种限制,即字符$c$出现的次数为$cnt$,若一个字符有多种限制,则满足任意一个 ...

  4. [Leetcode] Remove duplicate from sorted list ii 从已排序的链表中删除重复结点

    Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numb ...

  5. 安徽师大附中%你赛day3T1 怜香惜玉 解题报告

    怜香惜玉 题意: 已知 \(f(x)=\frac{2 \times \sum_{(i,x)=1}^x i}{φ(x)}\) 先给定数据组数\(t\)和\(k\) 每组数据给出\(n\),求\(\sum ...

  6. 笔记本电脑上面安装linux网络配置以及ping通问题

    ping不同,XShell连接不上linux: 360全部关闭,即可. 具体参考: http://blog.csdn.net/xiezhaoxuan/article/details/52673236 ...

  7. TCP ------ TCP四次挥手(断开连接)及断开过程

    1.正常情况下,调用close(),产生的其中一个效果就是发送FIN,只有双方都调用close(),才会出现正常的四次挥手. 2.如果是服务器,发起四次挥手是在关闭accept()返回的套接字,而不是 ...

  8. 对比append插入数据产生的redo量

    --版本信息 SELECT * FROM v$version; Oracle - Prod PL - Production CORE Production TNS - Production NLSRT ...

  9. linux下解压,压缩命令大全---方便新手查看

    本文最后讲述如何在打包时排除某些文件 .tar 解包:tar xvf FileName.tar 打包:tar cvf FileName.tar DirName (注:tar是打包,不是压缩!) --- ...

  10. CommonJs/ES6/AMD模块的用法以及区别

    github地址: 一直以来对CommonJs/AMD/CMD/ES6的文件模块加载一直懵懵懂懂.甚至有时会将CommonJs的exports和ES6的export.default搞混.趁着学习web ...