题目链接: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的每个素因子的幂指数,即可求解

代码如下:

#include<bits/stdc++.h>
using namespace std;
const double eps = 1e-; long long prime[], p = ;
bool is_prime[]; void init()
{
memset(is_prime, true, sizeof(is_prime));
for(int i=; i<=; ++ i)
{
if(is_prime[i])
{
prime[p++] = i;
for(int j=i; j<=; j+=i)
is_prime[j] = false;
}
}
} void solve(int cases)
{
long long n;
scanf("%lld", &n);
long long ans = ;
for(int i=; i<p&&prime[i]*prime[i]<=n; ++ i)
{
int res = ;
while(n % prime[i] == )
{
n /= prime[i];
res ++;
}
ans *= (res + );
}
if(n > )
ans *= ;
printf("Case %d: %lld\n", cases, ans-);
} int main()
{
int n;
scanf("%d", &n);
init();
for(int i=; i<=n; ++i)
{
solve(i);
}
return ;
}

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. 网络转载——java接口的概念

    为什么会出现接口? 接口的出现是为了扩展java中的类继承的单调性.这样使得功能更加丰富. 接口关键字? 定义接口interface,实现一个接口  implements 什么接口呢? 接口是一种特殊 ...

  2. AX 插入一条记录提示表记录已经存在,但是该记录实际上是不存在的。

    做测试的时候遇到一个情况"AX 插入一条记录提示表记录已经存在,但是该记录实际上是不存在的." 检查到该表(TABLE_ABC)所有的key都是AllowDuplicate的, 继 ...

  3. java学习第16天(泛型 增强for)

    泛型概述 是一种把明确类型的工作推迟到创建对象或者调用方法的时候才去明确的特殊的类型.格式: <数据类型> 注意:该数据类型只能是引用类型. 好处:避免了强制类型转换,比如上个实验   S ...

  4. Leetcode3:Longest Substring Without Repeating Characters@Python

    Given a string, find the length of the longest substring without repeating characters. Examples: Giv ...

  5. 29. Xshell连接Linux下Oracle无法回退的解决办法

    使用Xshell 连接远程Linux 数据库服务器,当切换到sqlplus 控制台时,输入错误字符的时候,使用回退键修改时,显示^H. 解决方法:切换至root用户,直接输入stty erase ^H ...

  6. formValidator表单验证示例

    <script type="text/javascript">$(document).ready(function(){ $.formValidator.initCon ...

  7. 错误C4146的解决方法

    error C4146: 一元负运算符应用于无符号类型,结果仍为无符号类型: 那么什么情况下会遇见这种错误呢,例如下代码: 错误代码1:int number = -2147483648; //erro ...

  8. zt:synpify 综合,保持信号,时序处理

    http://www.actel.com/kb/article.aspx?id=TT1002 Logic Replication vs. Preserve Attributes in Synplici ...

  9. oracle 客户端单独配置

    本文目的是在CentOS 5.3上安装Oracle 11.2 instant client来访问远端的Oracle 10.2数据库,笔者测试通过,应该也适用于Redhat Linux 5.x     ...

  10. Centos7上安装dnf-plugins-core

    为了在Centos上使用dnf copr命令,需要安装dnf-plugins-core,找了很长时间,包括试了源码编译安装都不行,最后找到了方法,执行下面的命令就可以了. 需要root权限 wget ...