Codeforces 1017F The Neutral Zone(数论好题)

本文介绍了一种新颖的数学概念exlogf,并通过具体的示例解释了如何利用多项式函数来解决与该概念相关的复杂计算问题。此外,文章还分享了实现高效算法的经验,包括使用bitset进行位压缩优化和埃式筛法改进。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

F. The Neutral Zone

time limit per test
5 seconds
memory limit per test
16 megabytes
input
standard input
output
standard output

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+…+aklogpk
Where pa11pa22…pa2k

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)

Notice that exlogf(1)
is always equal to 0

.

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

).

“Class is over! Don’t forget to do your homework!” Here it is: n∑i=1exlogf(i)

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

.
Input

The only line contains five integers n
, A, B, C, and D (1≤n≤3⋅108, 0≤A,B,C,D≤106

).
Output

Print the answer modulo 232

.
Examples
Input
Copy

12 0 0 1 0

Output
Copy

63

Input
Copy

4 1 2 3 4

Output
Copy

136

Note

In the first sample:

exlogf(1)=0

exlogf(2)=2

exlogf(3)=3

exlogf(4)=2+2=4

exlogf(5)=5

exlogf(6)=2+3=5

exlogf(7)=7

exlogf(8)=2+2+2=6

exlogf(9)=3+3=6

exlogf(10)=2+5=7

exlogf(11)=11

exlogf(12)=2+2+3=7

∑12i=1exlogf(i)=63

In the second sample:

exlogf(1)=0

exlogf(2)=(1×23+2×22+3×2+4)=26

exlogf(3)=(1×33+2×32+3×3+4)=58

exlogf(4)=2×exlogf(2)=52

∑4i=1exlogf(i)=0+26+58+52=136

有篇博客写的非常好,我就不班门弄斧了(其实懒得写了)

传送门

不过这确实是道好题

学习到了以下几点:

1.取模 232 2 32 实际上就是用unsigned int直接计算让他自然溢出

2.使用bitset进行位压,实际上这是我第二次做到用bitset的题

3.埃式筛如果把2和3的倍数都去掉的话,剩下的数按照从1-n排列,每个数的标号相当于这个数除3,这样大大节省了内存开销

code:

#include <bits/stdc++.h>
using namespace std;
unsigned int n,a,b,c,d;
unsigned int ans;
bitset<100000001> bit;
inline unsigned int f(unsigned int x){
    return a * x * x * x + b * x * x + c * x + d;
}
inline unsigned int Get(unsigned int x){
    unsigned int ret = f(x);
    unsigned int tmp = 0;
    for(unsigned int i = 1; i <= n / x; i *= x){
        tmp += n / (i * x);
    }
    return ret * tmp;
}
int main(){
    while(~scanf("%u%u%u%u%u",&n,&a,&b,&c,&d)){
        ans = Get(2) + Get(3);
        bit.reset();
        for(unsigned int i = 5; i <= n; i++){
            if(i % 2 == 0 || i % 3 == 0){
                continue;
            }
            if(bit[i/3] == 0){
                ans += Get(i);
                for(unsigned int j = i; j <= n; j += i){
                    if(j % 2 == 0 || j % 3 == 0) continue;
                    bit[j/3] = 1;
                }
            }
        }
        printf("%u\n",ans);
    }
    return 0;
}
### Codeforces 目列表获取方式 对于希望在Codeforces上寻找目进行练习的用户而言,可以通过访问Codeforces官方网站并导航至竞赛页面来浏览不同类型的目。具体来说,在网站主页上方菜单栏中选择“Problemset”,这里包含了大量历史比赛中的目供用户筛选[^1]。 为了更高效地找到适合自己的练习,可以利用页面右侧的一系列过滤条件,比如通过标签(Tags)、难度等级(Rating)或是特定的比赛名称来进行精准查找。例如,如果对组合数学感兴趣或者想要挑战与之相关的算法问,“Combinatorics”就是一个不错的标签选项;而针对新手用户,则可以从较低评级开始尝试逐步提升难度。 另外值得注意的是,除了直接搜索之外,还可以关注官方举办的各类赛事公告以及社区内其他用户的推荐资源,这些都能帮助发现更多优质习。 ```python import requests from bs4 import BeautifulSoup def fetch_codeforces_problems(): url = 'https://codeforces.com/problemset' response = requests.get(url) soup = BeautifulSoup(response.text,'html.parser') problems_table = soup.find('table',{'class':'problems'}) rows = problems_table.findAll('tr')[1:] # 跳过表头 result = [] for row in rows: cols = row.findAll('td') problem_info = { "index": cols[0].text.strip(), "name": cols[1].a['title'], "link": f"https://codeforces.com{cols[1].a['href']}" } result.append(problem_info) return result[:5] # 返回前五个作为示例 fetch_codeforces_problems() ``` 此段Python代码展示了如何爬取Codeforces Problemset页面的部分数据,并将其整理成易于阅读的形式返回给调用者。当然实际应用时还需要考虑异常处理等问以确保程序稳定性。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值