Light OJ 1028 - Trailing Zeroes (I) (数学-因子个数)
题目链接: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) (数学-因子个数)的更多相关文章
- light oj 1138 - Trailing Zeroes (III)【规律&&二分】
1138 - Trailing Zeroes (III) PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: ...
- Light oj 1138 - Trailing Zeroes (III) 【二分查找 && N!中末尾连续0的个数】
1138 - Trailing Zeroes (III) problem=1138"> problem=1138&language=english&type=pdf&q ...
- 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 ...
- LightOj1028 - Trailing Zeroes (I)---求因子个数
题目链接:http://lightoj.com/volume_showproblem.php?problem=1028 题意:给你一个数 n (1<=n<=10^12), 然后我们可以把它 ...
- Light oj 1138 - Trailing Zeroes (III) (二分)
题目链接:http://lightoj.com/volume_showproblem.php?problem=1138 题目就是给你一个数表示N!结果后面的0的个数,然后让你求出最小的N. 我们可以知 ...
- LightOJ 1028 - Trailing Zeroes (I) 质因数分解/排列组合
题意:10000组数据 问一个数n[1,1e12] 在k进制下有末尾0的k的个数. 思路:题意很明显,就是求n的因子个数,本来想直接预处理欧拉函数,然后拿它减n就行了.但注意是1e12次方法不可行.而 ...
- [LintCode] Trailing Zeroes 末尾零的个数
Write an algorithm which computes the number of trailing zeros in n factorial. Have you met this que ...
- 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 ...
- Light OJ 1032 - Fast Bit Calculations(数学)
题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1032 题目大意:一个十进制数变化为二进制,那么对于这个数,如果连着两个二进制位 ...
随机推荐
- ORA-04021:timeout occurred while waiting to lock object
编译某存储过程 ORA-04021 timeout occurred while waiting to lock object stringstringstringstringstring Cause ...
- 百度echart使用心得,百度图表。
百度echart算是百度针对数据展示做的一个图表插件吧,一般我们使用都不是问题,主要还是对于对动态数据的解析.我这里使用饼状图,和柱状图为例: 首先,我们需要定义一个绘图的容器:(class是我自己定 ...
- LR12.53—使用HP网络导游示例应用程序
本教程使用 的HP Web之旅,一个样本的基于Web的旅行社系统,向人们展示LoadRunner将如何作为负载测试解决方案.惠普网络旅游用户连接到Web服务器,搜索航班,预订机票,检查飞行路线. 虽然 ...
- win2008下安装SQL SERVER 2005出现IIS功能要求 警告解决方案
原因: 出现此问题的原因取决于 SQL Server 的不是所有 IIS 7.0 组件都安装在计算机上.下表列出了受影响的组件. 收起该表格展开该表格 组件 文件夹 静态内容 常见的 HTTP 功 ...
- 使用Maven来写j2ee项目
第一步:使用Maven创建web项目 是不是很简单? 第二步 问题 很多人,创建好后是没有src/main/java的源文件的,解决办法: 1.直接new ResourceFloder,src/mai ...
- 矩阵乘法的MapReduce实现
对于任意矩阵M和N,若矩阵M的列数等于矩阵N的行数,则记M和N的乘积为P=M*N,其中mik 记做矩阵M的第i行和第k列,nkj记做矩阵N的第k行和第j列,则矩阵P中,第i行第j列的元素可表示为公式( ...
- c#的dllimport使用方法详解,调试找不到dll的方法
DllImport会按照顺序自动去寻找的地方: 1.exe所在目录 2.System32目录 3.环境变量目录所以只需要你把引用的DLL 拷贝到这三个目录下 就可以不用写路径了 或者可以这样serve ...
- MongoDB服务重启及后台运行解决方法
1 在MongoDB 安装目录下 新建一个test文件夹 mkdir /test 2 切换到MongoDB的安装目录(可通过 find -name 'mongod'命令查找安装目录)下 执行: bin ...
- 解锁scott用户及设置密码
关于Oracle 10g scott用户解锁的方法两则 解决方法一. 首先确认已经安装oracle 数据库和客户端 在客户端DOS下执行如下语句: 注意提示符号 c:\sqlplus /nolog s ...
- sqlserver 查看正在执行sql
SELECT [session_id], [request_id], [cpu_time], [start_time] AS '开始时间', [status] AS '状态', [co ...