题目:输出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. Servlet的学习之Cookie

    从本篇开始学习Servlet技术中的Cookie专题. 首先来了解什么是“会话”.会话是web技术中的一个术语,可以简单的理解为:用户打开一个浏览器,点击多个超链接,访问服务器多个web资源,然后关闭 ...

  2. cPickle.so:: PyUnicodeUCS2_DecodeUTF8

    cPickle.so:: PyUnicodeUCS2_DecodeUTF8错误 Python编译的参数,和Python module(mod_wsgi, pymodwsgi)编译参数不一,导致一些un ...

  3. J2EE SSH学习(二)安装Eclipse插件和第一个Eclipse项目

    (一)安装Eclipse插件 Eclipse有很多功能很强大的插件,我现在作为一个菜鸟只知道插件的功能通常都很牛叉实用或者很有趣,那么该怎么安装Eclipse插件呢? 我使用的是Eclipse 4.3 ...

  4. 用yum查询想安装的软件

    1.使用YUM查找软件包  命令:yum search~  2.列出所有可安装的软件包  命令:yum list  3.列出所有可更新的软件包  命令:yum list updates  4.列出所有 ...

  5. centos7 opera济览器安装

    网网下rpm安装包: http://www.opera.com/computer/thanks?partner=www&par=id%3D39136%26amp;location%3D403& ...

  6. c vs c++ in strcut and class

    c vs c++ in strcut and class 总习惯用c的用法,现在学习C++,老爱拿来比较.声明我用的是g++4.2.1 SUSE Linux.看例子吧 #include <ios ...

  7. 海蜘蛛网络科技官方网站 :: 做最好的中文软路由 :: 软件路由器 :: 软路由 :: 软件路由 :: RouterOs

    海蜘蛛网络科技官方网站 :: 做最好的中文软路由 :: 软件路由器 :: 软路由 :: 软件路由 :: RouterOs 企业简介 武汉海蜘蛛网络科技有限公司成立于2005年,是一家专注于网络新技术研 ...

  8. centos 安装 redis3.2.0 集群

    这里创建6个redis节点,其中三个为主节点,三个为从节点. redis和端口对应关系: 127.0.0.1:7000 127.0.0.1:7001 127.0.0.1:7002 从: 127.0.0 ...

  9. extjs desktop startmenu (開始菜单)

    extjs desktop 的開始菜单 二级菜单,仅仅是简单演示实现原理,如 须要动态生成,自己改造就可以,下面基本方法原理: 首先 建立一个js文件 生成開始菜单数据:  function Get ...

  10. thinkphp3.2入口文件

    原文:thinkphp3.2入口文件 <?php define('DIR_SECURE_FILENAME', 'default.html');//错误页面 define('APP_PATH',' ...