题目:输出n!中素数因数的个数。

分析:数论。这里使用欧拉筛法计算素数,在计算过程中求解就可以。

传统筛法是利用每一个素数,筛掉自己的整数倍;

欧拉筛法是利用当前计算出的全部素数,乘以当前数字筛数;

所以每一个前驱的素椅子个数一定比当前数的素因子个数少一个。

说明:重新用了“线性筛法”。

#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <cmath> using namespace std; int prime[1000001];
int visit[1000001];
int numbe[1000001];
int sums[1000001]; int main()
{
//筛法计算素数
memset(visit, 0, sizeof(visit));
memset(numbe, 0, sizeof(numbe));
int count = 0;
for (int i = 2 ; i < 1000001 ; ++ i) {
if (!visit[i]) {
prime[count ++] = i;
numbe[i] = 1;
}
for (int j = 0 ; j < count && i*prime[j] < 1000001 ; ++ j) {
visit[i*prime[j]] = 1;
numbe[i*prime[j]] = numbe[i]+1;
}
sums[i] = sums[i-1] + numbe[i];
} int n;
while (~scanf("%d",&n))
printf("%d\n",sums[n]); return 0;
}

UVa 884 - Factorial Factors的更多相关文章

  1. uva 129 krypton factors ——yhx

     Krypton Factor  You have been employed by the organisers of a Super Krypton Factor Contest in which ...

  2. UVa 11621 - Small Factors

    称号:发现没有比给定数量少n的.只要2,3一个因素的数字组成. 分析:数论.贪婪,分而治之. 用两个三分球,分别代表乘法2,和繁殖3队列,队列产生的数字,原来{1}. 然后.每取两个指针相应元素*2和 ...

  3. UVa 324 - Factorial Frequencies

    题目大意:给一个数n,统计n的阶乘中各个数字出现的次数.用java的大数做. import java.io.*; import java.util.*; import java.math.*; cla ...

  4. 【数论】Factors of Factorial @upcexam6503

    问题 G: Factors of Factorial 时间限制: 1 Sec  内存限制: 128 MB提交: 57  解决: 33[提交][状态][讨论版][命题人:admin] 题目描述 You ...

  5. UVA 160 - Factors and Factorials

     Factors and Factorials  The factorial of a number N (written N!) is defined as the product of all t ...

  6. UVA 10699 Count the factors 题解

    Time limit 3000 ms OS Linux Write a program, that computes the number of different prime factors in ...

  7. Factors of Factorial AtCoder - 2286 (N的阶乘的因子个数)(数论)

    Problem Statement You are given an integer N. Find the number of the positive divisors of N!, modulo ...

  8. UVA 1575 Factors

    https://vjudge.net/problem/UVA-1575 题意: 令f(k)=n 表示 有n种方式,可以把正整数k表示成几个数的乘积的形式. 例 10=2*5=5*2,所以f(10)=2 ...

  9. B - Factors of Factorial

    Problem Statement You are given an integer N. Find the number of the positive divisors of N!, modulo ...

随机推荐

  1. ASP.NET - 跳转页面

    1. Response.Redirect("../Manager/AddBookInfoImages.aspx?id=" + Server.UrlEncode(ReturnValu ...

  2. 2007LA 3902 网络(树+贪心)

    https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&category=283&am ...

  3. Complete Guide for Spring Boot Actuator

    You are here to learn about Spring Boot Actuator for collecting metrics about your production grade ...

  4. BUG: scheduling while atomic: events/0/4/总结

    对于Linux内核来说,Oops就意外着内核出了异常,此时会将产生异常时CPU的状态,出错的指令地址.数据地址及其他寄存器,函数调用的顺序甚至是栈里面的内容都打印出来,然后根据异常的严重程度来决定下一 ...

  5. Excel设置下拉选项的方法

    前些日子参加提高班组织的数据采集工作,到各个二级学院搜集数据,当然离不开我们常用的Excel表格了.在这次采集数据的过程过程中还真学到了一两招.就比如在Excel中设置下拉选项的方法. 例如我们要在A ...

  6. OpenStack优先

    http://www.lagou.com/jobs/1623064.html http://www.lagou.com/jobs/1406144.html

  7. web.xml中listener作用及使用

    一.WebContextLoaderListener 监听类 它能捕捉到server的启动和停止,在启动和停止触发里面的方法做对应的操作! 它必须在web.xml 中配置才干使用,是配置监听类的 二. ...

  8. HTML属性

  9. git版本号回滚

    先说今天遇到的问题,看到一个config.php的配置文件一直在改动的状态下,可是和远程的config.php是不一致的,我不须要提交它,可是看它在 modified的状态下,非常不爽.想删除它.gi ...

  10. linux 软连接 硬连接

    1.Linux链接概念 Linux链接分两种,一种被称为硬链接(Hard Link),另一种被称为符号链接(Symbolic Link).默认情况下,ln命令产生硬链接. [硬连接] 硬连接指通过索引 ...