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),求所有符 ...
随机推荐
- 【原创】Linux基础之opensuse15
装机 装机之后执行 sudo zypper ar -fc https://mirrors.aliyun.com/opensuse/distribution/leap/15.0/repo/oss ope ...
- js用replaceAll全部替换的方法
1 前言 js中字符串整体替换,只有自带的replace,并没有replaceAll,如果我们需要把字符串中的字符统一替换,可以用正则表达式,由于经常使用就在String直接加个原生方法,方便调用. ...
- ubuntu18.04安装xmind8
1.先去官网下载:https://www.xmind.net/download/xmind8/ 2.默认下载到/home/guojihai/下载/目录下然后把xmind-8-update8-linux ...
- Python下划线的详解
本文将讨论Python中下划线(_)字符的使用方法.我们将会看到,正如Python中的很多事情,下划线的不同用法大多数(并非所有)只是常用惯例而已. 单下划线(_) 通常情况下,会在以下3种场景中使用 ...
- 使用VW时,图片的问题
在项目中,使用了VW适配,给图片直接设置了width和height,浏览器模拟正常,在手机上就不显示 解决办法是:在图片外面包一层div,设置width和height,然后图片设置width:100% ...
- oracle 11g完全彻底的卸载
1.关闭oracle所有的服务.可以在windows的服务管理器中关闭: 2.打开注册表:regedit 打开路径: <找注册表 :开始->运行->regedit> HKEY ...
- ADO.NET连接字符串大全---各种数据库的连接字符串
ADO.NET连接字符串大全 ADO.NET连接字符串 名称 ADO.NET连接字符串 说明 ADO.NET连接字符串:SQL Server,SQL Server 2005,ACCESS,Oracle ...
- mysql5.7设置简单密码报错ERROR 1819 (HY000): Your password does not satisfy the current policy requirements
注:本文来源于< mysql5.7设置简单密码报错ERROR 1819 (HY000): Your password does not satisfy the current policy r ...
- Confluence 6 启用 HTTP 压缩
在屏幕的右上角单击 控制台按钮 ,然后选择 基本配置(General Configuration) 链接. 在左侧的面板中选择 通用配置(General Configuration). 启用 HTTP ...
- Confluence 6 让 Jira 应用停止发送通知到 Confluence
你可能希望仅仅配置 Confluence 在 workbox 中仅仅显示自己的通知,禁用在 workbox 中显示从 Jira 来的通知.有可能这个 Jira 的应用已经通过应用链接功能正确链接到 C ...