1 //#include <bits/stdc++.h>
2 #include<cstdio>
3 #include<cstring>
4 #include<algorithm>
5 #include<iostream>
6 #include<string>
7 #include<vector>
8 #include<stack>
9 #include<bitset>
10 #include<cstdlib>
11 #include<cmath>
12 #include<set>
13 #include<list>
14 #include<deque>
15 #include<map>
16 #include<queue>
17
18 using namespace std;
19
20 const int N = 1000010;
21
22 typedef long long LL;
23 LL TT,nn,k;
24 namespace Min25 {
25
26 int prime[N], id1[N], id2[N], flag[N], ncnt, m;
27
28 LL g[N], sum[N], a[N], T, n;
29 inline void fff()
30 {
31 for(int i=0;i<=N;i++){
32 prime[i]=0;
33 id1[i]=0;
34 id2[i]=0;
35 flag[i]=0;
36 g[i]=0;
37 sum[i]=0;
38 a[i]=0;
39 }
40 ncnt=0;
41 m=0;
42 T=0;
43 n=0;
44 }
45 inline int ID(LL x) {
46 return x <= T ? id1[x] : id2[n / x];
47 }
48
49 inline LL calc(LL x) {
50 return x * (x + 1) / 2 - 1;
51 }
52
53 inline LL f(LL x) {
54 return x;
55 }
56
57 inline void init() {
58 T = sqrt(n + 0.5);
59 for (int i = 2; i <= T; i++) {
60 if (!flag[i]) prime[++ncnt] = i, sum[ncnt] = sum[ncnt - 1] + i;
61 for (int j = 1; j <= ncnt && i * prime[j] <= T; j++) {
62 flag[i * prime[j]] = 1;
63 if (i % prime[j] == 0) break;
64 }
65 }
66 for (LL l = 1; l <= n; l = n / (n / l) + 1) {
67 a[++m] = n / l;
68 if (a[m] <= T) id1[a[m]] = m; else id2[n / a[m]] = m;
69 g[m] = calc(a[m]);
70 }
71 for (int i = 1; i <= ncnt; i++)
72 for (int j = 1; j <= m && (LL)prime[i] * prime[i] <= a[j]; j++)
73 g[j] = g[j] - (LL)prime[i] * (g[ID(a[j] / prime[i])] - sum[i - 1]);
74 }
75
76 inline LL solve(LL x) {
77 if (x <= 1) return x;
78 return n = x, init(), g[ID(n)];
79 }
80
81 }
82
83 void extend_gcd(LL a,LL b,LL &x,LL &y)
84 {
85 if(b==0) {
86 x=1,y=0;
87 return;
88 }
89 extend_gcd(b,a%b,x,y);
90 LL tmp=x;
91 x=y;
92 y=tmp-(a/b)*y;
93 }
94 LL mod_inverse(LL a,LL m)
95 {
96 LL x,y;
97 extend_gcd(a,m,x,y);
98 return (m+x%m)%m;
99 }
100 /*int main()
101 {
102 LL sum;
103 cin>>TT;
104 while(TT--){
105 sum=0;
106
107 scanf("%lld%lld",&nn,&k);
108 if(nn==1){
109 printf("0\n");
110 }else if(nn==2){
111 printf("6\n");
112 }else{
113 LL a=mod_inverse(2,k);
114 //cout<<a<<endl;
115 sum=(((((nn%k)*(nn%k))%k+(nn*3)%k)%k)*a)%k;
116 //cout<<sum<<endl;
117 Min25::fff();
118 sum=(sum-4+Min25::solve(nn+1))%k;
119 printf("%lld\n",sum%k);
120 }
121 }
122 return 0;
123 }*/
124 int main()
125 {
126 int n;
127 scanf("%d",&n);
128 printf("%d\n",Min25::solve(n));
129 }
//#include <bits/stdc++.h>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<stack>
#include<bitset>
#include<cstdlib>
#include<cmath>
#include<set>
#include<list>
#include<deque>
#include<map>
#include<queue>
using namespace std;
const int N = 1000010;
typedef long long LL;
LL TT,nn,k;
namespace Min25 {
    int prime[N], id1[N], id2[N], flag[N], ncnt, m;
  
    LL g[N], sum[N], a[N], T, n;
    inline void fff()
    {
        for(int i=0;i<=N;i++){
            prime[i]=0;
            id1[i]=0;
            id2[i]=0;
            flag[i]=0;
            g[i]=0;
            sum[i]=0;
            a[i]=0;
        }
        ncnt=0;
        m=0;
        T=0;
        n=0;
    }
    inline int ID(LL x) {
        return x <= T ? id1[x] : id2[n / x];
    }
    inline LL calc(LL x) {
        return x * (x + 1) / 2 - 1;
    }
    inline LL f(LL x) {
        return x;
    }
    inline void init() {
        T = sqrt(n + 0.5);
        for (int i = 2; i <= T; i++) {
            if (!flag[i]) prime[++ncnt] = i, sum[ncnt] = sum[ncnt - 1] + i;
            for (int j = 1; j <= ncnt && i * prime[j] <= T; j++) {
                flag[i * prime[j]] = 1;
                if (i % prime[j] == 0) break;
            }
        }
        for (LL l = 1; l <= n; l = n / (n / l) + 1) {
            a[++m] = n / l;
            if (a[m] <= T) id1[a[m]] = m; else id2[n / a[m]] = m;
            g[m] = calc(a[m]);
        }
        for (int i = 1; i <= ncnt; i++) 
            for (int j = 1; j <= m && (LL)prime[i] * prime[i] <= a[j]; j++) 
                g[j] = g[j] - (LL)prime[i] * (g[ID(a[j] / prime[i])] - sum[i - 1]);
    }
    inline LL solve(LL x) {
        if (x <= 1) return x;
        return n = x, init(), g[ID(n)];
    }
}
void extend_gcd(LL a,LL b,LL &x,LL &y)
{
    if(b==0) {
        x=1,y=0;
        return;
    }
    extend_gcd(b,a%b,x,y);
    LL tmp=x;
    x=y;
    y=tmp-(a/b)*y;
}
LL mod_inverse(LL a,LL m)
{
    LL x,y;
    extend_gcd(a,m,x,y);
    return (m+x%m)%m;
}
/*int main()
{
    LL sum;
    cin>>TT;
    while(TT--){
        sum=0;
        scanf("%lld%lld",&nn,&k);
        if(nn==1){
            printf("0\n");
        }else if(nn==2){
            printf("6\n");
        }else{
        LL a=mod_inverse(2,k);
        //cout<<a<<endl;
        sum=(((((nn%k)*(nn%k))%k+(nn*3)%k)%k)*a)%k;
        //cout<<sum<<endl;
        Min25::fff();
        sum=(sum-4+Min25::solve(nn+1))%k;
        printf("%lld\n",sum%k);
        }
    }
    return 0;
}*/
int main()
{
    int n;
    scanf("%d",&n);
    printf("%d\n",Min25::solve(n));
}

Min25筛求1-n内的素数和的更多相关文章

  1. 问题 1084: 用筛法求之N内的素数。

    #include <iostream> #include <cstdio> #include <cstring> #include <string> # ...

  2. [总结] min-25筛

    再不写总结我又会忘掉啊啊啊啊啊啊啊啊啊 这个\(min-25\)筛主要用来求一个积性函数的前缀和,就像这样\[\sum_{i=1}^n f(i)\] 不过这个积性函数要满足两个条件:质数\(p\)的函 ...

  3. loj#6235. 区间素数个数(min25筛)

    题意 题目链接 Sol min25筛的板子题,直接筛出\(g(N, \infty)\)即可 筛的时候有很多trick,比如只存\(\frac{N}{x}\)的值,第二维可以滚动数组滚动掉 #inclu ...

  4. hdu6607 min25筛+杜教筛+伯努利数求k次方前缀和

    推导过程类似https://www.cnblogs.com/acjiumeng/p/9742073.html 前面部分min25筛,后面部分杜教筛,预处理min25筛需要伯努利数 //#pragma ...

  5. BZOJ-5244 最大真因数(min25筛)

    题意:一个数的真因数指不包括其本身的所有因数,给定L,R,求这个区间的所有数的最大真因数之和. 思路:min25筛可以求出所有最小因子为p的数的个数,有可以求出最小因子为p的所有数之和. 那么此题就是 ...

  6. 「学习笔记」Min25筛

    「学习笔记」Min25筛 前言 周指导今天模拟赛五分钟秒第一题,十分钟说第二题是 \(\text{Min25}​\) 筛板子题,要不是第三题出题人数据范围给错了,周指导十五分钟就 \(\text{AK ...

  7. min25筛学习总结

    前言 杜教筛学了,顺便把min25筛也学了吧= =刚好多校也有一道题需要补. 下面推荐几篇博客,我之后写一点自己的理解就是了. 传送门1 传送门2 传送门3 这几篇写得都还是挺好的,接下来我就写下自己 ...

  8. CodeForces - 83D:Numbers (数学&递归 - min25筛 )

    pro:给定三个整数L,R,P求[L,R]区间的整数有多少个是以P为最小因子的.L,R,P<2e9; sol: 一: 比较快的做法是,用函数的思想递归. 用solve(N,P)表示求1到N有多少 ...

  9. Min25筛

    Min25筛 我是沙雕... 从yyb博客蒯的 要求:\(\sum_{i=1}^nF(x)\) \(F(x)\)是积性函数. \(Min25\)筛能用的前提:质数处的\(f(p)\)值是关于\(p\) ...

随机推荐

  1. 前端接收后端文件流导出excel文档遇到的问题

    先上代码: Vue.prototype.download = function(oUrl, filename) { this.axios .get(oUrl, { responseType: 'arr ...

  2. Shell 编程快速上手

    Shell 编程快速上手 test.sh #!/bin/sh cd ~ mkdir shell_tut cd shell_tut for ((i=0; i<10; i++)); do touch ...

  3. 开放式 Web 应用程序安全性项目 OWASP

    开放式 Web 应用程序安全性项目 OWASP Open Web Application Security Project (OWASP) OWASP 基金会是谁? Open Web Applicat ...

  4. Awesome Gatsby blog websites

    Awesome Gatsby blog websites very simple very clean i18n dark mode (css var) demos https://overreact ...

  5. cache-control config & http cache storage location control

    cache-control config & http cache storage location control cache-control 设置 where is the storage ...

  6. Flutter & QRCode App

    Flutter & QRCode App https://github.com/xgqfrms/qrcode-reader-app how to open android emulator o ...

  7. Node.js & ES modules & .mjs

    Node.js & ES modules & .mjs Node.js v13.9.0 https://nodejs.org/api/esm.html https://nodejs.o ...

  8. React SSR in Action

    React SSR in Action react render HTML string from the server ReactDOMServer https://reactjs.org/docs ...

  9. lua调用dll导出的函数

    参考手册 hello.dll #include "pch.h" #include "lua.hpp" #pragma comment(lib, "lu ...

  10. ts 修改readonly参数

    readonly name = "xxx"; updateValueAndValidity(): void { // this.name = 'a'; (this as { nam ...