One of the biggest, most mathematicians would call it THE biggest, unsolved problems in mathematics is the proof of the Riemann Hypothesis: “All non-trivial zeros of the zeta function have real part onehalf”. Now your task is simple: For any natural number N, give the N-th zero… nah, just kidding! That would be a much too complex problem for an online contest. We’ll leave Riemann and the zeta function and concern ourselves with the closely related, but much easier to calcultate Mertens’s function. For those interested in the subject I can heartly recommend Derbyshire’s book (see the epilogue).
    Every positive natural number greater than 1, can be uniquely decomposed into it’s prime factors. Some numbers have only one factor, namely the number itself, like 2, 11 and 71, and are caled prime numbers. Others have more than one factor, like 4 (2×2), 15 (3×5) and 144 (2×2×2×2×3×3), and are called composite numbers. If a number contains all it’s prime factors only once, it is called square free. All prime numbers are square free. Some composite numbers are square free, like 21 (3×7) and 187 (11×17), others are not, like 9 (3×3) and 98 (2×7×7).
Let’s define the Mobius function mu(N), for all positive natural numbers N:
• mu(1) = 1, by definition;
• if N is not square free, mu(N) = 0;
• if N is square free and contains an even number of prime factors, mu(N) = 1;
• if N is square free and contains an odd number of prime factors, mu(N) = −1.
    Now we can define Mertens’s function M(N) as the sum of all mu() for 1 up to and including N: M(N) = mu(1) + mu(2) + . . . + mu(N).
The first 20 values for both functions are in this table:

N factors mu(N) M(N)
1 - 1 1
2 2 -1 0
3 3 -1 -1
4 22 0 -1
5 5 -1 -2
6 23 1 -1
7 7 -1 -2
8 222 0 -2
9 33 0 -2
10 25 1 -1
11 11 -1 -2
12 223 0 -2
13 13 -1 -3
14 27 1 -2
15 35 1 -1
16 2222 0 -1
17 17 -1 -2
18 233 0 -2
19 19 -1 -3
20 225 0 -3

We want you to calculate mu(N) and M(N) for some values of N
Input
Up to 1000 numbers between 1 and 1000000 (one million), both included, each on a line by itself. The numbers are in random order and can appear more than once. Input is terminated by a line, which contains a single zero. This line should not be processed.
Output
For each number in the input print that number, the value of mu() for that number and the value of M() for that number, all three on one line, right justified in fields of width 8. The input order must be preserved.
Sample Input
20
1
144
73
0
Sample Output

      20        0      -31          1       1144       0     -173       -1     -4

问题链接:UVA10738 Riemann vs Mertens
问题简述:(略)
问题分析:数论筛法问题,不解释。
程序说明:(略)
参考链接:(略)
题记:(略)

AC的C++语言程序如下:

/* UVA10738 Riemann vs Mertens */#include <bits/stdc++.h>using namespace std;// 欧拉筛法
const int N = 1000000;
bool isprime[N + 1];
int prime[N / 3], pcnt = 0;
void eulersieve(void)
{memset(isprime, true, sizeof(isprime));isprime[0] = isprime[1] = false;for(int i = 2; i <= N; i++) {if(isprime[i])prime[pcnt++] = i;for(int j = 0; j < pcnt && i * prime[j] <= N; j++) {  //筛选isprime[i * prime[j]] = false;if(i % prime[j] == 0) break;}}
}int mu[N + 1], mn[N + 1];void init()
{mu[1] = mn[1] = 1;for (int i = 2; i <= N; i++) {int a = 0, n = i;for (int j = 0; j < pcnt && prime[j] * prime[j] <= n; j++)if (n % prime[j] == 0) {a++;if (n / prime[j] % prime[j] == 0) {a = -100;break;}n /= prime[j];}if (n != 1) a++;if (a < 0) mu[i] = 0;else if (a % 2 == 1) mu[i] = -1;else mu[i] = 1;mn[i] = mn[i - 1] + mu[i];}
}int main()
{eulersieve();init();int n;while (~scanf("%d", &n) && n)printf("%8d%8d%8d\n", n, mu[n], mn[n]);return 0;
}

UVA10738 Riemann vs Mertens【欧拉筛法】相关推荐

  1. 质数c语言欧拉筛选,Python|欧拉筛法求质数

    欢迎点击「算法与编程之美」↑关注我们! 本文首发于微信公众号:"算法与编程之美",欢迎关注,及时了解更多此系列文章. 问题描述 我们知道第一个质数是 2.第二个质数是 3.第三个质 ...

  2. 素数计算之埃氏筛法、欧拉筛法

    埃氏筛法 int main() {const int maxNumber=200;int isPrime[maxNumber];int i;int x;for (i=0;i<maxNumber; ...

  3. UVA516 POJ1365 LA5533 ZOJ1261 Prime Land【欧拉筛法】

    Everybody in the Prime Land is using a prime base number system. In this system, each positive integ ...

  4. UVA12043 Divisors【欧拉筛法】

    Let us define the functions d(n) and σ(n) as d(n)=numberofdivisorsofnd(n) = number of divisors of nd ...

  5. UVA12039 Goldbach‘s Cardinality【欧拉筛法】

    Goldbach's cardinality (GC) of an even number means the number of ways the even number can be expres ...

  6. UVA11876 N + NOD (N)【欧拉筛法+前缀和】

    Consider an integer sequence N where, N0 = 1 Ni = Ni−1 + NOD(Ni−1) for i > 0     Here, NOD(x) = n ...

  7. 欧拉筛法(线性筛)的学习理解

    前言 在刚接触编程语言时,对于寻找素数,第一时间想到的便是二重循环暴力查找,其复杂度O(n^2),通过循环中只判断到根号n可以优化一些,不过复杂度也达不到预期.在数论的学习中,我学到了埃氏筛法,O(n ...

  8. 筛质数—(朴素筛法、埃氏筛法、欧拉筛法(线性筛法))

    筛质数时首先要了解质数的定理:1~n中有  个质数 下面再来看具体算法: 1.朴素筛法: 直接把2~n-1中质数和合数的倍数都筛一遍,其代码如下所示: int primes[N],cnt=0; boo ...

  9. 素数筛法(传统普通、朴素筛法、埃式筛法、欧拉筛法(线性筛))

    素数筛法(普通.朴素筛法.埃式筛法.欧拉筛法) 1.题目 2.分析 3.代码 传统普通 朴素筛法 朴素筛法(6.14) 埃式筛法 埃式筛法(6.14) 欧拉筛法(线性筛) 欧拉筛法(线性筛 6.14) ...

最新文章

  1. springboot-web开发(rest风格支持)
  2. 用python写一个简单的爬虫_用Python编写一个简单的爬虫
  3. 荆门市掇刀石中学2021高考成绩查询,2021年荆门中考所有高中学校排名 荆门重点高中分数线...
  4. UI5 Navigation execution entry point
  5. Magicodes.IE 2.5.6.2发布
  6. 三十、详测 Generics Collections: TObjectList、TObjectQueue、TObjectStack
  7. FlashFXP列表参数错误解决方法
  8. 响应信息有json和html,获取HTML响应而不是Json响应
  9. 常用排序+查找算法时间复杂度大集合
  10. 把项目中任意文件夹导出为可执行的jar包
  11. 88se9230 linux raid,Marvell发布全球首颗PCI-E 2.0 x2 SATA 6Gbps主控
  12. windows 设置定时锁屏
  13. 前期观看郝斌老师Java学习视频整理的部分笔记
  14. 动作捕捉——从模型到动画个人流程记录
  15. SPF(最短路径树)算法
  16. 2023湖南师范大学计算机考研信息汇总
  17. django tests 小结
  18. AT学习报告一 软件的初步使用
  19. 网页连接服务器失败是怎么回事,网页怎么连接服务器失败是怎么回事
  20. 美国旅游签证办理流程

热门文章

  1. 2019-12-18 syscall(SYS_clock_gettime, CLOCK_MONOTONIC_RAW
  2. java提示没有main,有main方法却还是提示没有
  3. ArcGIS水文分析实战教程(18) 河段桩号与线性参考
  4. 【自我救赎--牛客网Top101 4天刷题计划】 第四天 登峰造极
  5. php高德地图计算距离接口,高德地图计算两坐标之间距离
  6. Intellij IDEA的配置
  7. java工程如何使用ivew_vue+iview搭建项目
  8. linux暂时不能域名解析,Kali Linux中暂时不能解析域名
  9. python 知乎 合并 pdf_32.使用selenium爬取知乎,并实现多页保存为一个PDF文件
  10. Java依赖多个版本,java – Gradle中的多个依赖项版本