J. Sum

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.

题意:

令F(i)表示满足x*y=i,且x和y都不包含平方数因子的合法(x,y)对数,求∑F(i)

思路:

很容易证明F(i)是积性函数,如果i中不存在3次方以上的质因子,F(i) = 2^(i中只出现一次的质因子个数),否则F(i) = 0

那么就是个积性函数前缀和的问题了

很多项都为0,利用Min_25筛可以在1s内轻松解决范围内的所有询问

#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<map>
#include<string>
#include<math.h>
#include<queue>
#include<stack>
#include<iostream>
using namespace std;
#define LL long long
#define mod 1000000007
#define er 500000004
int cnt, s[200005], id[200005], B, m, h[200005];
bool flag[200005];
LL n, w[200005], pri[200005];
void Primeset(int n)
{int i, j;for(i=2;i<=n;i++){if(flag[i]==0){pri[++cnt] = i;s[cnt] = s[cnt-1]+i;}for(j=1;j<=cnt&&i*pri[j]<=n;j++){flag[i*pri[j]] = 1;if(i%pri[j]==0)break;}}
}
LL F(LL x, int y)
{LL t1;int i, k, e, ans;if(x<=1 || pri[y]>x)return 0;if(x>B)k = n/x;if(x<=B)k = id[x];ans = 2*(h[k]-(y-1));for(i=y;i<=cnt&&(LL)pri[i]*pri[i]<=x;i++){t1 = pri[i];for(e=1;t1*pri[i]<=x;e++){if(e==1)ans = (ans+(F(x/t1, i+1)*2+1));else if(e==2)ans = (ans+F(x/t1, i+1));t1 *= pri[i];}}return ans;
}int main(void)
{LL i, j, k, last;int T;scanf("%d", &T);while(T--){m = cnt = 0;scanf("%lld", &n);B = sqrt(n), Primeset(B);for(i=1;i<=n;i=last+1){w[++m] = n/i;h[m] = w[m]-1;last = n/(n/i);if(n/i<=B)id[n/i] = m;}for(j=1;j<=cnt;j++){for(i=1;i<=m&&pri[j]*pri[j]<=w[i];i++){if(w[i]/pri[j]<=B)k = id[w[i]/pri[j]];elsek = n/(w[i]/pri[j]);h[i] = h[i]-(h[k]-(j-1));}}printf("%lld\n", (F(n, 1)+1));}return 0;
}

2018ACM-ICPC南京赛区网络赛: J. Sum(积性函数前缀和)相关推荐

  1. ACM-ICPC 2018 南京赛区网络预赛 J Sum(欧拉线性筛+思维)

    Sum 问题分析 题意:我们将类似于6=2⋅36=2⋅36 = 2\cdot 3这样的数称为asquare−freeintegerasquare−freeintegera\:square-free\: ...

  2. 2014 ACM/ICPC 北京赛区网络赛解题报告汇总

    首页 算法竞赛» 信息聚合 ONLINE JUDGE 书刊杂志 BLOG» 新闻故事» 招聘信息» 投稿须知 2014 ACM/ICPC 北京赛区网络赛解题报告汇总 九月 21st, 2014 | P ...

  3. 2011 ACM/ICPC 福州赛区网络赛解题报告

    第一次写网络赛的题解,福州赛区网络赛作为我第一年ACM最后一次网络赛酱油,画了一个很像逗号的句号.....好吧,还得为北京现场赛准备啊准备....... 这次酱油打的很犀利,貌似出第一题很快,之后节奏 ...

  4. 2014 ACM/ICPC 鞍山赛区网络赛(清华命题)

    为迎接10月17号清华命题的鞍山现场赛 杭电上的题目 Biconnected(hdu4997)     状态压缩DP Rotate(hdu4998)    相对任一点的旋转 Overt(hdu4999 ...

  5. 2018 ACM/ICPC 北京赛区网络赛 D 80 Days 线段树

    http://hihocoder.com/problemset/problem/1831?sid=1390457 描述 80 Days is an interesting game based on ...

  6. ACM-ICPC 2018 南京赛区网络预赛 J AC Challenge (状压dp)

    题意 给你n道题,在你做第ii{i}道题的时候有p[j]p[j]{p[j]}个前置条件,当这些前置条件都满足的时候,我们可以得到a[j]∗t+b[j]a[j]∗t+b[j]a[j] * t + b[j ...

  7. 2018ACM-ICPC南京赛区网络赛: B. The writing on the wall

    B. The writing on the wall 题目链接:https://nanti.jisuanke.com/t/30991 题意: 给你一个n*m的矩阵, 其中有些格子上面有障碍物,问有多少 ...

  8. luogu 1327 数列排序 2017 ACM-ICPC 亚洲区(南宁赛区)网络赛 J题 循环节

    luogu 1327 数列排序 题意 给定一个数列\(\{an\}\),这个数列满足\(ai≠aj(i≠j)\),现在要求你把这个数列从小到大排序,每次允许你交换其中任意一对数,请问最少需要几次交换? ...

  9. 2019 ICPC 徐州网络赛 J.Random Access Iterator

    2019 ICPC 徐州网络赛 J.Random Access Iterator 题目大意:给你n个点和n-1条边(树形结构),保证1为根节点,通过以下方式dfs遍历: 询问dfs到最深节点的概率(有 ...

最新文章

  1. Scikit-learn环境的搭建
  2. SetWindowOrg等相关函数
  3. Solr4.7从数据库导数据
  4. 图解Spark On Yarn cluster模式运行机制
  5. 机器学习 异常值检测_异常值是否会破坏您的机器学习预测? 寻找最佳解决方案
  6. BeetleX实现MessagePack和Protobuf消息控制器调用websocket服务详解
  7. python基础(16)之 日期
  8. 20170513 Python练习册0011过滤敏感词
  9. 注册信息表html,实战系列 —— HTML 的 “注册信息表”
  10. Windows环境下 node 取消 npm install 采用软连接引用node_modules
  11. vue nextTick深入理解-vue性能优化、DOM更新时机、事件循环机制
  12. java day56【 Mybatis 延迟加载策略 、 Mybatis 缓存、Mybatis 注解开发 】
  13. Idea-Plugin编写Android Studio插件
  14. 鬼压床、清明梦、外星劫持……睡眠麻痹症能够解释这些都市传说吗?
  15. 03 【Nginx虚拟主机和域名解析】
  16. 淘宝美工掌握这4种能力,不逊色于UI设计师
  17. JAVA :一张纸厚0.5mm //0.0005m,折叠多少次,厚度会超过珠穆朗玛峰?(8848.43m)
  18. 浅谈vue的生命周期
  19. StatQuest系列之t-SNE
  20. 机器学习-Sklearn-01(决策树)

热门文章

  1. python编程-Python3 网络编程
  2. 只有10万元预算买畅销SUV自动车型您选谁?
  3. 语音识别技术应用领域介绍
  4. “语音识别”+“视觉识别” - AI将引爆智能硬件市场 科技大佬们是这么认为的?...
  5. SpringCloud--Eureka 注册中心原理及其搭建
  6. 【堆笔记】java堆(PriorityQueue)的相关操作
  7. 【python笔记】python基础(注释,缩进,变量,表达式,运算符)
  8. LeetCode 106/105 从中序和后序/前序遍历序列构造二叉树
  9. ijkplayer-添加播放截图功能
  10. 基于运动特征的视频质量评价方法(基于H.264)