题目:输出n!中素数因数的个数。

分析:数论。这里使用欧拉筛法计算素数,在计算过程中求解就可以。

传统筛法是利用每一个素数,筛掉自己的整数倍;

欧拉筛法是利用当前计算出的全部素数,乘以当前数字筛数;

所以每一个前驱的素椅子个数一定比当前数的素因子个数少一个。

说明:重新用了“线性筛法”。

  1. #include <algorithm>
  2. #include <iostream>
  3. #include <cstdlib>
  4. #include <cstring>
  5. #include <cstdio>
  6. #include <cmath>
  7.  
  8. using namespace std;
  9.  
  10. int prime[1000001];
  11. int visit[1000001];
  12. int numbe[1000001];
  13. int sums[1000001];
  14.  
  15. int main()
  16. {
  17. //筛法计算素数
  18. memset(visit, 0, sizeof(visit));
  19. memset(numbe, 0, sizeof(numbe));
  20. int count = 0;
  21. for (int i = 2 ; i < 1000001 ; ++ i) {
  22. if (!visit[i]) {
  23. prime[count ++] = i;
  24. numbe[i] = 1;
  25. }
  26. for (int j = 0 ; j < count && i*prime[j] < 1000001 ; ++ j) {
  27. visit[i*prime[j]] = 1;
  28. numbe[i*prime[j]] = numbe[i]+1;
  29. }
  30. sums[i] = sums[i-1] + numbe[i];
  31. }
  32.  
  33. int n;
  34. while (~scanf("%d",&n))
  35. printf("%d\n",sums[n]);
  36.  
  37. return 0;
  38. }

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. SpringMVC从Control中响应json数据

    在页面上异步获取Controller中响应的json数据. <%@ page language="java" contentType="text/html; cha ...

  2. Processing_百度百科

    Processing_百度百科 Processing

  3. CorePlot学习

    阅读这篇文章,指出它在国外    原文地址:https://github.com/core-plot/core-plot/wiki/High-Level-Design-Overview 强烈推荐阅读该 ...

  4. js弹出对话框,遮罩效果,

    刚刚来到实习单位,我跟着廖哥做项目.然后他分配给我一个小小的任务,实现起来总的效果如下: 然后,但我们单击显示数目这个链接的时候,就会弹出一个又遮罩效果的对话框,如下图: 当我们在对话框中再点击里面的 ...

  5. Oracle 12C 简介

    2013年6月26日,Oracle Database 12c版本正式发布,首先发布的版本号是12.1.0.1.0,率先提供下载的平台有Linux和Solaris: Oracle官方下载地址: http ...

  6. 一个网友写的栈,问为啥不能迭代。具有__iter__ 和next方法的对象叫迭代器-七七巴巴黄页网

    一个网友写的栈,问为啥不能迭代.具有__iter__ 和next方法的对象叫迭代器-七七巴巴黄页网 一个网友写的栈,问为啥不能迭代.具有__iter__ 和next方法的对象叫迭代器 python视频 ...

  7. spring开发基础

    Spring是一个开源框架,它由Rod Johnson创建.它是为了解决企业应用开发的复杂性而创建的.Spring使用基本的JavaBean来完成以前只可能由EJB完成的事情.然而,Spring的用途 ...

  8. UVA 10313(完全背包变形)

    Problem B Pay the Price Input: standard input Output: standard output Time Limit: 2 seconds Memory L ...

  9. 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 ...

  10. MySQL HINT:Straight_JOIN

    来自生产环境的朋友.可能都会碰到:          原本运行良好的查询语句,过了一段时间后,可能会突然变得很糟糕     一个很大可能的原因就是数据分布情况发生了变化     从而导致MySQL优化 ...