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 ...
随机推荐
- cell中button怎么得到对应cell的indexpath 以及关于UITableViewCellContentView的问题
============================================================ 博文原创,转载请声明出处 电子咖啡-专注于移动互联网 ============ ...
- 《转》OpenStack Live Migration
This post is based assumption that KVM as hypervisor, and Openstack is running in Grizzly on top of ...
- php运行
运行命令: $php 1.php php教程: http://www.w3school.com.cn/php/php_variables.asp
- Swift - 复杂数据类型说明(数组,字典,结构体,枚举)
1,数组 - Array 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 var types ...
- Swift编程语言学习9—— 存储属性和计算属性
属性将值跟特定的类.结构或枚举关联.存储属性存储常量或变量作为实例的一部分,计算属性计算(而不是存储)一个值.计算属性能够用于类.结构体和枚举里,存储属性仅仅能用于类和结构体. 存储属性和计算属性通经 ...
- ios王云鹤--iPhone中,点击换行,键盘消失。
1.要在声明文件中实现 UItextFieldDelegate 协议 2.在实现文件中实现 UItextFieldDelegate 协议 中键盘消失的方法即: -(BOOL)textFieldShou ...
- Windows7WithSP1/TeamFoundationServer2012update4/SQLServer2012
[Info @09:03:33.737] ====================================================================[Info @ ...
- HDU 3911 Black And White 分段树 题解
Problem Description There are a bunch of stones on the beach; Stone color is white or black. Little ...
- DB2错误码解释对照
表 2. SQLSTATE 类代码 类 代码 含义 要获得子代码, 参阅... 00 完全成功完成 表 3 01 警告 表 4 02 无数据 表 5 07 动态 SQL 错误 表 6 ...
- [转]PHP 5.2~5.6 对照以及功能具体解释
[分享]PHP 5.2~5.6 对照以及功能具体解释 作者:流水理鱼wwek 来源:http://www.iamle.com/archives/1530.html 截至眼下(2014.2), PHP ...