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 ...
随机推荐
- SpringMVC从Control中响应json数据
在页面上异步获取Controller中响应的json数据. <%@ page language="java" contentType="text/html; cha ...
- Processing_百度百科
Processing_百度百科 Processing
- CorePlot学习
阅读这篇文章,指出它在国外 原文地址:https://github.com/core-plot/core-plot/wiki/High-Level-Design-Overview 强烈推荐阅读该 ...
- js弹出对话框,遮罩效果,
刚刚来到实习单位,我跟着廖哥做项目.然后他分配给我一个小小的任务,实现起来总的效果如下: 然后,但我们单击显示数目这个链接的时候,就会弹出一个又遮罩效果的对话框,如下图: 当我们在对话框中再点击里面的 ...
- Oracle 12C 简介
2013年6月26日,Oracle Database 12c版本正式发布,首先发布的版本号是12.1.0.1.0,率先提供下载的平台有Linux和Solaris: Oracle官方下载地址: http ...
- 一个网友写的栈,问为啥不能迭代。具有__iter__ 和next方法的对象叫迭代器-七七巴巴黄页网
一个网友写的栈,问为啥不能迭代.具有__iter__ 和next方法的对象叫迭代器-七七巴巴黄页网 一个网友写的栈,问为啥不能迭代.具有__iter__ 和next方法的对象叫迭代器 python视频 ...
- spring开发基础
Spring是一个开源框架,它由Rod Johnson创建.它是为了解决企业应用开发的复杂性而创建的.Spring使用基本的JavaBean来完成以前只可能由EJB完成的事情.然而,Spring的用途 ...
- UVA 10313(完全背包变形)
Problem B Pay the Price Input: standard input Output: standard output Time Limit: 2 seconds Memory L ...
- LeetCode——Populating Next Right Pointers in Each Node II
Follow up for problem "Populating Next Right Pointers in Each Node". What if the given tre ...
- MySQL HINT:Straight_JOIN
来自生产环境的朋友.可能都会碰到: 原本运行良好的查询语句,过了一段时间后,可能会突然变得很糟糕 一个很大可能的原因就是数据分布情况发生了变化 从而导致MySQL优化 ...