Notice: unusual memory limit!

After the war, destroyed cities in the neutral zone were restored. And children went back to school.

The war changed the world, as well as education. In those hard days, a new math concept was created.

As we all know, logarithm function can be described as:

log(pa11pa22...pa2k)=a1logp1+a2logp2+...+aklogpklog⁡(p1a1p2a2...pka2)=a1log⁡p1+a2log⁡p2+...+aklog⁡pk

Where pa11pa22...pa2kp1a1p2a2...pka2 is the prime factorization of a integer. A problem is that the function uses itself in the definition. That is why it is hard to calculate.

So, the mathematicians from the neutral zone invented this:

exlogf(pa11pa22...pa2k)=a1f(p1)+a2f(p2)+...+akf(pk)exlogf(p1a1p2a2...pka2)=a1f(p1)+a2f(p2)+...+akf(pk)

Notice that exlogf(1)exlogf(1) is always equal to 00.

This concept for any function ff was too hard for children. So teachers told them that ff can only be a polynomial of degree no more than 33 in daily uses (i.e., f(x)=Ax3+Bx2+Cx+Df(x)=Ax3+Bx2+Cx+D).

"Class is over! Don't forget to do your homework!" Here it is:

∑i=1nexlogf(i)∑i=1nexlogf(i)

Help children to do their homework. Since the value can be very big, you need to find the answer modulo 232232.

Input

The only line contains five integers nn, AA, BB, CC, and DD (1≤n≤3⋅1081≤n≤3⋅108, 0≤A,B,C,D≤1060≤A,B,C,D≤106).

Output

Print the answer modulo 232232.

Examples

Input
12 0 0 1 0
Output
63
Input
4 1 2 3 4
Output
136

题意:给定函数Fx=A*x^3+B*x^2+C*x+D; 而函数Fx=Fa1+Fa2+...,当且仅当x=p1^a1+p2^a2+...

思路:很显然我们是算关于每个素数p的函数,Fp。然后乘其贡献次数nump。 Fp可以算,nump=N/p+N/p/p+N/p/p/p+....

N以内的素数个数约有N/lnN个,所以算每个素数的nump复杂度为O(NlglgN),可以搞。那么现在的关键就是在16M,5s的空间和时间里筛出3e8的素数。

显然压空间可以用bitset,bitset存1e8的空间只需要12.5M。再利用2,3以外的素数==6x+-1,压缩一下就搞定了。 以下代码筛3e8的素数只需要250ms。

void prime()
{
add(); add(); //单独考虑
for(UI i=,d=;i<=N;i+=d,d=-d) {
if(!p[i/]){
add(i); if(i>N/i) continue;
for(UI j=i*i,v=d;j<=N;j+=i*v,v=-v) p[j/] = ;
}
}
}

所以,搞定! 当然,也可以用区间筛法,一段一段的搞定。

#include<bits/stdc++.h>
using namespace std;
typedef unsigned int UI;
UI ans,N,A,B,C,D;
bitset<>p;
inline void add(UI x) {
UI f=A*x*x*x+B*x*x+C*x+D;
for(UI t=N;t;t/=x) ans+=t/x*f;
}
void prime()
{
add(); add(); //单独考虑
for(UI i=,d=;i<=N;i+=d,d=-d) {
if(!p[i/]){
add(i); if(i>N/i) continue;
for(UI j=i*i,v=d;j<=N;j+=i*v,v=-v) p[j/] = ;
}
}
}
int main() {
scanf("%u%u%u%u%u",&N,&A,&B,&C,&D);
prime();
printf("%u\n", ans);
return ;
}

CodeForces - 1017F. The Neutral Zone (数学+Bitset存素数+素数筛优化)的更多相关文章

  1. Codeforces 1017F The Neutral Zone (看题解)

    这题一看就筛质数就好啦, 可是这怎么筛啊, 一看题解, 怎么会有这么骚的操作. #include<bits/stdc++.h> #define LL long long #define f ...

  2. Codeforces 1017F The Neutral Zone 数论

    原文链接https://www.cnblogs.com/zhouzhendong/p/CF1017F.html 题目传送门 - CF1017F 题意 假设一个数 $x$ 分解质因数后得到结果 $x=p ...

  3. 【CF1017F】The Neutral Zone(Bitset,埃氏筛)

    题意: 思路:From https://blog.csdn.net/CSDNjiangshan/article/details/81536536 #include<cstdio> #inc ...

  4. Codeforces 789e The Great Mixing (bitset dp 数学)

    Sasha and Kolya decided to get drunk with Coke, again. This time they have k types of Coke. i-th typ ...

  5. Codeforces Gym 100342J Problem J. Triatrip bitset 求三元环的数量

    Problem J. TriatripTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100342/att ...

  6. Codeforces 577B Modulo Sum:数学 结论【选数之和为m的倍数】

    题目链接:http://codeforces.com/problemset/problem/448/C 题意: 给你n个数字,给定m. 问你是否能从中选出若干个数字,使得这些数字之和为m的倍数. 题解 ...

  7. [Codeforces 1178D]Prime Graph (思维+数学)

    Codeforces 1178D (思维+数学) 题面 给出正整数n(不一定是质数),构造一个边数为质数的无向连通图(无自环重边),且图的每个节点的度数为质数 分析 我们先构造一个环,每个点的度数都是 ...

  8. Z - New Year Tree CodeForces - 620E 线段树 区间种类 bitset

    Z - New Year Tree CodeForces - 620E 这个题目还没有写,先想想思路,我觉得这个题目应该可以用bitset, 首先这个肯定是用dfs序把这个树转化成线段树,也就是二叉树 ...

  9. Codeforces 1225G - To Make 1(bitset+状压 dp+找性质)

    Codeforces 题目传送门 & 洛谷题目传送门 还是做题做太少了啊--碰到这种题一点感觉都没有-- 首先我们来证明一件事情,那就是存在一种合并方式 \(\Leftrightarrow\) ...

随机推荐

  1. python利用正则表达式提取字符串

    前言 正则表达式的基础知识就不说了,有兴趣的可以点击这里,提取一般分两种情况,一种是提取在文本中提取单个位置的字符串,另一种是提取连续多个位置的字符串.日志分析会遇到这种情况,下面我会分别讲一下对应的 ...

  2. 【BZOJ3270】博物馆 期望DP+高斯消元

    [BZOJ3270]博物馆 Description 有一天Petya和他的朋友Vasya在进行他们众多旅行中的一次旅行,他们决定去参观一座城堡博物馆.这座博物馆有着特别的样式.它包含由m条走廊连接的n ...

  3. EasyDSS视频点播服务器实现多分辨率/多码率无缝切换的办法

    EasyDSS流媒体音视频直播与点播服务器软件,是一套提供一站式的转码.点播.直播.检索.回放.录像下载服务的高性能RTMP/HLS/HTTP-FLV流媒体服务,极大地简化了流媒体相关业务的开发和集成 ...

  4. douban_转自熊博网——牛逼顿

    转自熊博网——牛逼顿 来自: 天云之叶(大道易得,小术难求) 2010-04-21 18:32:27 牛逼顿 作者:singularitys 3月28号是牛顿的忌日,但是知道的人很少,我们毕竟更关心沈 ...

  5. java web Listener的简单使用案例

    1.web.xml的配置 <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi= ...

  6. [ubuntu]安装adobe air

    修改安装文件为可执行权限: sudo ./AdobeAIRInstaller.bin 提示错误: <code> Adobe AIR could not be installed. Inst ...

  7. Java & 混型

    1.C++ & 混型 C++能够记住其模板参数的类型,对于混型来说,使用参数化类型更加优雅. #include <string> #include <ctime> #i ...

  8. QT5使用Webkti

    Qt 5.3 使用原来的QT4.8.4项目时QWebView .QWebFrame等类无法编译通过. 出现原因:QWebView .QWebFrame.QWebPage.QWebInspector等这 ...

  9. 队列(Queue)

    队列(Queue) Queue: 先入先出(FIFO)的数据结构. offer,add区别: 一些队列有大小限制,因此如果想在一个满的队列中加入一个新项,多出的项就会被拒绝. 这时新的 offer 方 ...

  10. swift ! 和 ? 的学习

    刚开始学 这两个符号 不确定到底是否是可以互相替代 用的都混淆了 今天好好做个总结 如果声明一个变量 如下 var  name:String?  //只声明 没做初始化赋值 说明 当前name 是 n ...