Codeforces 1017F The Neutral Zone 数论
原文链接https://www.cnblogs.com/zhouzhendong/p/CF1017F.html
题目传送门 - CF1017F
题意
假设一个数 $x$ 分解质因数后得到结果 $x=p_1^{a_1}p_2^{a_2}\cdots p_k^{a_k} $
定义 $\text{exlog}_f(x) = a_1 f(p_1) + a_2 f(p_2) + ... + a_k f(p_k)$
给定 $A,B,C,D$ 表示 $f(x)=Ax^3+Bx^2+Cx+D$
求 $\sum_{i=1}^n \text{exlog}_f(i)$ 。
$n\leq 3\times 10^8,\ \ A,B,C,D\leq 10^6,\ \ $ 答案对于 $2^{32}$ 取模。
题解
考虑一个素数 $p$ 对答案的贡献。定义 $cnt(条件)$ 为 $1$~$n$ 中满足条件的数的个数。
显然,一个素数对答案的贡献是: $\sum_{i=1}^{\infty} cnt((x\mod {p^i}=0)\ and\ (x\mod {p^{i+1}}\neq 0))\times i \times f(p_i)$ 。
由于质数的个数大约在 $\cfrac{n}{\log(n)}$ 数量级,所以我们可以一个 $log$ 求上面的东西。
接下来的问题就是如何快速得到所有质数。
考虑一个大于 $3$ 的质数对于 $6$ 取模只可能是 $1$ 或 $5$ 。
这样,我们就把可能的范围缩小了 $3$ 倍。
空间限制很小,我们需要 32 位压位,然后之前又压了 $3$ 倍,空间刚好卡进 16MB。
然后就一边暴力筛出素数,一边求当前素数对于答案的贡献。
我的写法细节比较多,不推荐。可以考虑损失一点常数来做,会好写一些。
代码
#pragma GCC optimize("Ofast")
#pragma GCC optimize("inline")
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef unsigned uint;
LL read(){
LL x=0;
char ch=getchar();
while (!isdigit(ch))
ch=getchar();
while (isdigit(ch))
x=(x<<1)+(x<<3)+ch-48,ch=getchar();
return x;
}
uint n,A,B,C,D,ans=0;
uint fff[3333533];
// 6 - 1 5
uint F(uint v){
return A*v*v*v+B*v*v+C*v+D;
}
void update(uint p){
uint m=n,d=m/p,dd,i=0;
while (p<=d){
i++;
dd=d/p;
ans+=i*(d-dd)*F(p);
d=dd;
}
ans+=(i+1)*d*F(p);
}
int main(){
memset(fff,0,sizeof fff);
n=read(),A=read(),B=read(),C=read(),D=read();
for (uint i=2,f=0,k=0;i<=n;){
uint id=k<<1;
if (f==5)
id--;
if (i>5&&((fff[id>>5]>>(id&31))&1))
;
else {
// printf("%d\n",i);
update(i);
if (i>=5){
uint ii=i,ff=f,kk=k,iid,v1=4,v2=2;
if (f==5)
swap(v1,v2);
while (1){
if (ff==1)
ii+=v1*i,ff=5;
else
ii+=v2*i,ff=1;
if (ii>n)
break;
// printf("%u %u %u\n",ii,ff,kk);
kk=(ii+1)/6;
iid=kk<<1;
if (ii%6==5)
iid--;
fff[iid>>5]|=1<<(iid&31);
}
}
}
if (i<5){
if (i==2)
i=3;
else
i=5,f=5,k=1;
}
else if (f==1)
i+=4,f=5,k++;
else
i+=2,f=1;
}
printf("%u",ans);
return 0;
}
/*
100 0 0 0 1
*/
Codeforces 1017F The Neutral Zone 数论的更多相关文章
- CodeForces - 1017F. The Neutral Zone (数学+Bitset存素数+素数筛优化)
Notice: unusual memory limit! After the war, destroyed cities in the neutral zone were restored. And ...
- Codeforces 1017F The Neutral Zone (看题解)
这题一看就筛质数就好啦, 可是这怎么筛啊, 一看题解, 怎么会有这么骚的操作. #include<bits/stdc++.h> #define LL long long #define f ...
- [CodeForces - 1225D]Power Products 【数论】 【分解质因数】
[CodeForces - 1225D]Power Products [数论] [分解质因数] 标签:题解 codeforces题解 数论 题目描述 Time limit 2000 ms Memory ...
- Bash and a Tough Math Puzzle CodeForces 914D 线段树+gcd数论
Bash and a Tough Math Puzzle CodeForces 914D 线段树+gcd数论 题意 给你一段数,然后小明去猜某一区间内的gcd,这里不一定是准确值,如果在这个区间内改变 ...
- Codeforces 55D (数位DP+离散化+数论)
题目链接: http://poj.org/problem?id=2117 题目大意:统计一个范围内数的个数,要求该数能被各位上的数整除.范围2^64. 解题思路: 一开始SB地开了10维数组记录情况. ...
- Codeforces 833A The Meaningless Game - 数论 - 牛顿迭代法 - 二分法
Slastyona and her loyal dog Pushok are playing a meaningless game that is indeed very interesting. T ...
- Codeforces 837E Vasya's Function - 数论
Vasya is studying number theory. He has denoted a function f(a, b) such that: f(a, 0) = 0; f(a, b) = ...
- Codeforces 837D Round Subset - 动态规划 - 数论
Let's call the roundness of the number the number of zeros to which it ends. You have an array of n ...
- Codeforces 955C - Sad powers(数论 + 二分)
链接: http://codeforces.com/problemset/problem/955/C 题意: Q次询问(1≤Q≤1e5),每次询问给出两个整数L, R(1≤L≤R≤1e18),求所有符 ...
随机推荐
- 51nod--1298 (计算几何基础)
题目: 1298 圆与三角形 题目来源: HackerRank 基准时间限制:1 秒 空间限制:131072 KB 分值: 0 难度:基础题 收藏 关注 给出圆的圆心和半径,以及三角形的三个顶点,问圆 ...
- Laravel 5.2服务----用户验证Auth相关问题
关于laravel的auth()用户认证这一块,面前我也是,有用到,有碰到什么问题我就记录下来. 手动认证用户 <?php namespace App\Http\Controllers; use ...
- 洛谷P5072 [Ynoi2015]盼君勿忘 [莫队]
传送门 辣鸡卡常题目浪费我一下午-- 思路 显然是一道莫队. 假设区间长度为\(len\),\(x\)的出现次数为\(k\),那么\(x\)的贡献就是\(x(2^{len-k}(2^k-1))\),即 ...
- Modbus库开发笔记之八:CRC循环冗余校验的研究与实现
谈到Modbus通讯自然免不了循环冗余校验(CRC),特别是在标准的串行RTU链路上是必不可少的.不仅如此在其他开发中,也经常要用到CRC 算法对各种数据进行校验.这样一来,我们就需要研究一下这个循环 ...
- ORA-00845 MEMORY_TARGET not supported on this system 的解决
本文来源:宁静致远 的<ORA-00845 MEMORY_TARGET not supported on this system 的解决> oracle11g数据库在执行dbca或者调整s ...
- Confluence 6 创建站点的导出文件
希望为你的站点创建一个 XML 导出文件: 进入 > 基本配置(General Configuration) > 备份和恢复(Backup & Restore). 选择 归档到备 ...
- Confluence 6 在数据源连接中启用校验查询
确定 Confluence 在数据库连接池中校验数据库连接: 停止 Confluence. 编辑 <installation-directory>/conf/server.xml 文件(或 ...
- Confluence 6 连接到 Jira 用户管理的限制
当你在使用 JIRA 目录为用户目录的时候,请考虑下面的一些限制和建议. 不知道跨平台的多应用单点登录 当你使用 JIRA 为你的目录管理器的时候,系统将不能支持跨平台的单点登录.当 JIRA 用作目 ...
- jquery 获取和设置 select下拉框的值
获取Select : 获取select 选中的 text : $("#ddlRegType").find("option:selected").text(); ...
- Git 在webstrom上安装git
Git下载地址:https://git-scm.com/download/win 用webstorm迁入迁出代码时,首先要先下载git,网址一搜就可以搜到,然后开始配置webstorm,打开webst ...