UVa 884 - Factorial Factors
题目:输出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的更多相关文章
- uva 129 krypton factors ——yhx
Krypton Factor You have been employed by the organisers of a Super Krypton Factor Contest in which ...
- UVa 11621 - Small Factors
称号:发现没有比给定数量少n的.只要2,3一个因素的数字组成. 分析:数论.贪婪,分而治之. 用两个三分球,分别代表乘法2,和繁殖3队列,队列产生的数字,原来{1}. 然后.每取两个指针相应元素*2和 ...
- UVa 324 - Factorial Frequencies
题目大意:给一个数n,统计n的阶乘中各个数字出现的次数.用java的大数做. import java.io.*; import java.util.*; import java.math.*; cla ...
- 【数论】Factors of Factorial @upcexam6503
问题 G: Factors of Factorial 时间限制: 1 Sec 内存限制: 128 MB提交: 57 解决: 33[提交][状态][讨论版][命题人:admin] 题目描述 You ...
- UVA 160 - Factors and Factorials
Factors and Factorials The factorial of a number N (written N!) is defined as the product of all t ...
- UVA 10699 Count the factors 题解
Time limit 3000 ms OS Linux Write a program, that computes the number of different prime factors in ...
- Factors of Factorial AtCoder - 2286 (N的阶乘的因子个数)(数论)
Problem Statement You are given an integer N. Find the number of the positive divisors of N!, modulo ...
- UVA 1575 Factors
https://vjudge.net/problem/UVA-1575 题意: 令f(k)=n 表示 有n种方式,可以把正整数k表示成几个数的乘积的形式. 例 10=2*5=5*2,所以f(10)=2 ...
- B - Factors of Factorial
Problem Statement You are given an integer N. Find the number of the positive divisors of N!, modulo ...
随机推荐
- Apriori算法实现
Apriori算法原理:http://blog.csdn.net/kingzone_2008/article/details/8183768 import java.util.HashMap; imp ...
- python httpConnection详解
模块urllib,urllib2,httplib的区别 httplib实现了http和https的客户端协议,但是在python中,模块urllib和urllib2对httplib进行了更上层的封装. ...
- 理清JavaScript正则表达式
理清JavaScript正则表达式--下篇 紧接:"理清JavaScript正则表达式--上篇". 正则在String类中的应用 类String支持四种利用正则表达式的方法.分别是 ...
- c# in depth之泛型的实现
1.默认值表达式 如果已经明确了要处理的类型,也就知道了它的“默认”值.不知道要引用的类型,就不能直接指定默认值.不能使用null,因为它可能不是一个引用类型,不能使用0,因为它可能不是数值类型.虽然 ...
- linux脚本初体验
前言 第一次写linux脚本,有点紧张. 1. 写一个寻找特定用户的脚本文件? #! /bin/sh who | grep $1 其中脚本第一行用来告诉kernel去使用/bin/sh来解释这个脚本: ...
- VC++6.0和VS2005在编写MFC应用程序时,操作方面的差异
VC++6.0和VS2005在编写MFC应用程序时,操作方面的差异 一直用VC++6.0,对VS2005不太了解,下面简单的熟悉一下VS2005的一下功能,总结一下VS2005在编写MFC时候的应用. ...
- CodeForces 21C Stripe 2 构造题
题目链接: 题目链接:点击打开链接 #include <cstdio> #include <cstring> #include <algorithm> #inclu ...
- Android开发按返回键应用后台运行
@Override public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE ...
- nginx源代码分析--模块分类
ngx-modules Nginx 基本的模块大致能够分为四类: handler – 协同完毕client请求的处理.产生响应数据.比方模块, ngx_http_rewrite_module, ngx ...
- 【夯实基础】Spring在ssh中的作用
尊重版权:http://blog.csdn.net/qjlsharp/archive/2009/03/21/4013255.aspx 写的真不错. 在SSH框假中spring充当了管理容器的角色.我们 ...