题目链接: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 socket 通讯

    (转)http://blog.csdn.net/xn4545945/article/details/8098646

  2. AngularJS-系统代码的配置和翻译

    前言:在Web开发中常常会遇到这样的情况,有些页面的下拉选项是固定不变的几个,比如:性别,一般有男.女.保密等.对于这样的情形我们一般在数据库中存储的是数字或者其对应的代码,如果是可维护的需要系统给出 ...

  3. sql中limit使用方法

    此处以mysql为例,但是我相信物以变通在oracle上也一定适用 下面是几种limit的方法:原则看看下面几个例子应该就懂了 在数据库中很多地方都会用到,比如当你数据库查询记录有几万.几十万时使用l ...

  4. Python交互式编程导论----事件驱动编程

    传统的编程是如下线性模式的: 开始--->代码块A--->代码块B--->代码块C--->代码块D--->......--->结束 每一个代码块里是完成各种各样事情 ...

  5. Java设计模式--模板方法模式

    定义: 模板模式是一种行为设计模式,使用了JAVA的继承机制,在抽象类中定义一个模板方法,该方法引用了若干个抽象方法(由子类实现)或具体方法(子类可以覆盖重写).它的实现思路是,创建一个桩方法,并且定 ...

  6. QRCode二维码生成

    pom配置 <dependency> <groupId>com.github.cloudecho</groupId> <artifactId>qrcod ...

  7. 初识Promise

    Promise对象 曾经用seajs开发后台管理的时候,矫情的PHPER非要JS内联到HTML文件中,方便他调用内容,还指定了jQueryFileUpload作为上传插件. 当时看到jQueryFil ...

  8. python容器类型:列表,字典,集合等

    容器的概念我是从C++的STL中学到的 什么是容器? 容器是用来存储和组织其他对象的对象. 也就是说容器里面可以放很多东西,这些东西可以是字符串,可以是整数,可以是自定义类型,然后把这些东西有组织的存 ...

  9. python---IO多路复用

    这里的IO是指网络IO python中通过select模块实现IO多路复用,select模块中有select.poll.epoll等方法 下面例子以select模块实现IO多路复用 仅仅只有IO多路复 ...

  10. mysql5.7忘记密码

    注意:mysql5.7 user表密码字段由password改为authentication_string 1.service mysql stop 2.mysqld_safe --skip-gran ...