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 ...
随机推荐
- Servlet过滤器——创建过滤器
1.概述 介绍如何创建一个过滤器,并使用过滤器在打开页面的同时输出信息,此功能是由过滤器处理完成的. 2.技术要点 Serlvet过滤器实现了Filter接口,在Filter接口中定义了以下几个方法: ...
- delphi指针简单入门
delphi指针简单入门: 看一个指针用法的例子: 1 var 2 X, Y: Integer; // ...
- Android自学绝佳资料
本文转自stormzhang老师的博客:http://stormzhang.com/android/2014/07/07/learn-android-from-rookie 首先感谢stromzhan ...
- 基于visual Studio2013解决面试题之0403串联字符串
题目
- Ppoj 1014 深搜
这个题题意是给你价值1-6的珠宝个数输出能否平分为两份(如果平分为三分就不知道怎么做了……) 主要是用回溯DFS,但是要剪枝,对200取模……!!(很重要……) 代码…… #include <i ...
- Redis C客户端API - God's blog - 博客频道 - CSDN.NET
Redis C客户端API - God's blog - 博客频道 - CSDN.NET Redis安装步骤: 1.redis server安装 wget http://redis.googlecod ...
- Oracle中如何插入特殊字符:& 和 ' (多种解决方案)
今天在导入一批数据到Oracle时,碰到了一个问题:Toad提示要给一个自定义变量AMP赋值,一开始我很纳闷,数据是一系列的Insert语句,怎么会有自定义变量呢?后来搜索了一下关键字AMP发现,原来 ...
- NFS服务器端配置
服务器端配置1 创建共享目录# mkdir /home/share# chown nobody.nogroup /home/share2 创建或修改/etc/exports 配置文件这个文件的内容非常 ...
- Swift - 各种手势检测大全(UIGestureRecognizer及其子类)
UIGestureRecognizer有许多子类,用于监听一些常见的手势事件,这些子类主要有: 1,UISwipeGestureRecognizer:滑动(快速移动) 1 2 3 4 5 6 7 8 ...
- 深入分析 Java 中的中文编码问题(1)
几种常见的编码格式 为什么要编码 不知道大家有没有想过一个问题,那就是为什么要编码?我们能不能不编码?要回答这个问题必须要回到计算机是如何表示我们人类能够理解的符号的,这些符号也就是我们人类使用的语言 ...