题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1028

题目大意:n除了1有多少个因子(包括他本身)

解题思路:对于n的每个因子, 可以用n的所有素因子排列组合而来, n = (a1x1) * (a2 x2) * (a3x3)...*(anxn), 其中ai为n的素因子,那么n的因子的个数等同于(x1 + 1) * (x2 + 1) * (x3 + 1) ... * (xn + 1)中排列, 因为其中一种排列肯定为所有素因子的幂指数为0, 那么这个因子就是1, 这个最后去掉就好。 最后只求n的每个素因子的幂指数,即可求解

代码如下:

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. const double eps = 1e-;
  4.  
  5. long long prime[], p = ;
  6. bool is_prime[];
  7.  
  8. void init()
  9. {
  10. memset(is_prime, true, sizeof(is_prime));
  11. for(int i=; i<=; ++ i)
  12. {
  13. if(is_prime[i])
  14. {
  15. prime[p++] = i;
  16. for(int j=i; j<=; j+=i)
  17. is_prime[j] = false;
  18. }
  19. }
  20. }
  21.  
  22. void solve(int cases)
  23. {
  24. long long n;
  25. scanf("%lld", &n);
  26. long long ans = ;
  27. for(int i=; i<p&&prime[i]*prime[i]<=n; ++ i)
  28. {
  29. int res = ;
  30. while(n % prime[i] == )
  31. {
  32. n /= prime[i];
  33. res ++;
  34. }
  35. ans *= (res + );
  36. }
  37. if(n > )
  38. ans *= ;
  39. printf("Case %d: %lld\n", cases, ans-);
  40. }
  41.  
  42. int main()
  43. {
  44. int n;
  45. scanf("%d", &n);
  46. init();
  47. for(int i=; i<=n; ++i)
  48. {
  49. solve(i);
  50. }
  51. return ;
  52. }

Light OJ 1028 - Trailing Zeroes (I) (数学-因子个数)的更多相关文章

  1. light oj 1138 - Trailing Zeroes (III)【规律&&二分】

    1138 - Trailing Zeroes (III)   PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit:  ...

  2. Light oj 1138 - Trailing Zeroes (III) 【二分查找 &amp;&amp; N!中末尾连续0的个数】

    1138 - Trailing Zeroes (III) problem=1138"> problem=1138&language=english&type=pdf&q ...

  3. Light oj 1138 - Trailing Zeroes (III) 【二分查找好题】【 给出N!末尾有连续的Q个0,让你求最小的N】

    1138 - Trailing Zeroes (III) PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 32 ...

  4. LightOj1028 - Trailing Zeroes (I)---求因子个数

    题目链接:http://lightoj.com/volume_showproblem.php?problem=1028 题意:给你一个数 n (1<=n<=10^12), 然后我们可以把它 ...

  5. Light oj 1138 - Trailing Zeroes (III) (二分)

    题目链接:http://lightoj.com/volume_showproblem.php?problem=1138 题目就是给你一个数表示N!结果后面的0的个数,然后让你求出最小的N. 我们可以知 ...

  6. LightOJ 1028 - Trailing Zeroes (I) 质因数分解/排列组合

    题意:10000组数据 问一个数n[1,1e12] 在k进制下有末尾0的k的个数. 思路:题意很明显,就是求n的因子个数,本来想直接预处理欧拉函数,然后拿它减n就行了.但注意是1e12次方法不可行.而 ...

  7. [LintCode] Trailing Zeroes 末尾零的个数

    Write an algorithm which computes the number of trailing zeros in n factorial. Have you met this que ...

  8. lightoj 1028 - Trailing Zeroes (I)(素数筛)

    We know what a base of a number is and what the properties are. For example, we use decimal number s ...

  9. Light OJ 1032 - Fast Bit Calculations(数学)

    题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1032 题目大意:一个十进制数变化为二进制,那么对于这个数,如果连着两个二进制位 ...

随机推荐

  1. Windows server 2012远程桌面会话主机和远程桌面授权,server2012

    摘要:对于windows server2012服务器一般都是默认能够支持两用户远程登录,而通过安装远程桌面服务里的远程桌面会话主机和远程桌面授权,并对其进行配置,即可实现多用户远程登录. 远程桌面服务 ...

  2. JS-安全检测JavaScript基本数据类型和内置对象的方法

    前言:在前端开发中经常会需要用到检测变量数据类型的需求,比如:判断一个变量是否为undefined或者null来进行下一步的操作,今天在阅读“编写高质量代码-改善JavaScript程序的188个建议 ...

  3. STL之序列式容器list与forward_list

    List (双向链表) 与 forwardlist (单向链表) 算是非常基础的数据结构了,这里只是简单介绍下其结构及应用. 以list为例: 其节点模板: template <class T& ...

  4. asp.net静态变量的生命周期和线程安全

    void Application_Start开始 void Application_End结束的,本来这就是对的 今天要做一个全局的应用,想确认一下,在网上一找,我的天,说什么的都有 大概分三种 1. ...

  5. js面向对象的实现(example 二)

    //这个方法和上篇文章(js面向对象的实现(example 一))中的方法类似,但是更为简洁 //通过函数赋值的方式来构造对象 //同样通过闭包的方式来封装对象及内部变量 (function () { ...

  6. try-catch-finally 引发的奇怪问题

    今天,发现我们的一个Windows Service无法正常停止,无奈之下只能杀了进程. 为了找到原因,我在本地进行调试,发现程序里用到了多线程,而代码正是卡在了workThread.Abort()语句 ...

  7. 移动端rem页面详谈

    rem布局是移动端常见的布局之一,也是较为成熟的方案.接下来就详细说以下rem布局的实际操作. 1.首先加<meta />标签,设置视口的大小,不多说. <meta name=&qu ...

  8. Git 操作本地分支与远程分支

    1 查看本地分支 git branch 2 查看远程分支 git branch -a 3 新建远程分支 git checkout -b developr git push origin develop ...

  9. Nodejs学习(三)-安装nodejs supervisor,提高点效率吧。

    安装好了express准备写项目,可是发现随便改一下js都要使用npm start重新启动才能生效,这个很不好,搜索一下发现有这么一个模块supervisor.那就安装一下吧. 1.安装,这个必须是全 ...

  10. 配置Nginx支持SSL SNI(一个IP绑定多个证书) 以及Haproxy实现多域名证书

    概述 传统的每个SSL证书签发,每个证书都需要独立ip,假如你编译openssl和nginx时候开启TLS SNI (Server Name Identification) 支持,这样你可以安装多个S ...