We know what a base of a number is and what the properties are. For example, we use decimal number system, where the base is 10 and we use the symbols - {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}. But in different bases we use different symbols. For example in binary number system we use only 0 and 1. Now in this problem, you are given an integer. You can convert it to any base you want to. But the condition is that if you convert it to any base then the number in that base should have at least one trailing zero that means a zero at the end.

For example, in decimal number system 2 doesn't have any trailing zero. But if we convert it to binary then 2 becomes (10)2 and it contains a trailing zero. Now you are given this task. You have to find the number of bases where the given number contains at least one trailing zero. You can use any base from two to infinite.

Input

Input starts with an integer T (≤ 10000), denoting the number of test cases.

Each case contains an integer N (1 ≤ N ≤ 1012).

Output

For each case, print the case number and the number of possible bases where N contains at least one trailing zero.

题意:给定一个10进制数n, n <= 10 ^ 12, 问把它转换成哪一些进制的数,这个数末尾会有0。

其实就是问你他的约数个数,由于题中给的组数有点大10的4次直接求因子会超时,所以要换种方法求。

由于每个数都可以化为几个素数的积,所以可以利用这种思想

a=prime1^a1 * prime2^a2 * prime^a3......

sum=(a1 + 1) * (a2 + 1) * (a3 + 1)......

这题还有一些要优化的东西具体优化看一下代码。

#include <iostream>
#include <cstring>
#include <cmath>
#include <cstdio>
using namespace std;
typedef long long ll;
const int M = 1e6 + 10;
int prime[M];
int a[M];
bool isprime[M];
int counts;
void getprime() {
isprime[0] = isprime[1] = false;
isprime[2] = true;
for(int i = 3 ; i <= M ; i++) {
isprime[i] = i % 2 ? true : false;
}
int t = (int)sqrt(M * 1.0);
for(int i = 3 ; i <= t ; i++) {
if(isprime[i]) {
for(int j = i * i ; j <= M ; j += i) {
isprime[j] = false;
}
}
}
counts = 0;
for(int i = 2 ; i <= M ; i++) {
if(isprime[i]) {
prime[counts++] = i;
}
}
}
int main()
{
int t;
getprime();
scanf("%d" , &t);
int ans = 0;
while(t--) {
ans++;
ll n;
scanf("%lld" , &n);
ll sum = 1;
for(int i = 0 ; (ll)prime[i] * prime[i] <= n ; i++) {
int flag = 0;
while(n % prime[i] == 0) {
n /= prime[i];
flag++;
}
sum *= (flag + 1);
}
if(n > 1) {
sum *= 2;
}
sum--;
printf("Case %d: %lld\n" , ans , sum);
}
return 0;
}

lightoj 1028 - Trailing Zeroes (I)(素数筛)的更多相关文章

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

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

  2. LightOJ 1138 Trailing Zeroes (III)(二分 + 思维)

    http://lightoj.com/volume_showproblem.php?problem=1138 Trailing Zeroes (III) Time Limit:2000MS     M ...

  3. LightOj 1197 Help Hanzo 区间素数筛

    题意: 给定一个区间a,b,a-b>=100000,1<=a<=b<=231,求出给定a,b区间内的素数的个数 区间素数筛 (a+i-1)/ ii向上取整,当a为 i 的整数倍 ...

  4. Light OJ 1028 - Trailing Zeroes (I) (数学-因子个数)

    题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1028 题目大意:n除了1有多少个因子(包括他本身) 解题思路:对于n的每个因子 ...

  5. LightOj 1138 - Trailing Zeroes (III) 阶乘末尾0的个数 & 二分

    题目链接:http://lightoj.com/volume_showproblem.php?problem=1138 题意:给你一个数n,然后找个一个最小的数x,使得x!的末尾有n个0:如果没有输出 ...

  6. LightOj 1090 - Trailing Zeroes (II)---求末尾0的个数

    题目链接:http://lightoj.com/volume_showproblem.php?problem=1090 题意:给你四个数 n, r, p, q 求C(n, r) * p^q的结果中末尾 ...

  7. lightoj 1138 - Trailing Zeroes (III)【二分】

    题目链接:http://lightoj.com/volume_showproblem.php? problem=1138 题意:问 N. 末尾 0 的个数为 Q 个的数是什么? 解法:二分枚举N,由于 ...

  8. Lightoj 1090 - Trailing Zeroes (II)

    题目连接: http://www.lightoj.com/volume_showproblem.php?problem=1090 题目大意: 给出n,r,p,q四个数字1<=n,r,p,q< ...

  9. LightOJ 1138 Trailing Zeroes (III) 打表

    就是统计5,然后当时因为发现最多有8000w个5的倍数,然后8000w/100,是80w,打表,二分找 然后我看网上的都是直接二分找,真是厉害 #include <cstdio> #inc ...

随机推荐

  1. 关于定时器Scheduled(cron)的问题

    定时器配置步骤参考:http://blog.csdn.NET/sd4000784/article/details/7745947 下面给出cron参数中各个参数的含义: CRON表达式    含义 & ...

  2. Bean Validation完结篇:你必须关注的边边角角(约束级联、自定义约束、自定义校验器、国际化失败消息...)

    每篇一句 没有任何技术方案会是一种银弹,任何东西都是有利弊的 相关阅读 [小家Java]深入了解数据校验:Java Bean Validation 2.0(JSR303.JSR349.JSR380)H ...

  3. 两份简单的logstash配置

    input{http{port=>7474}} filter{ grok{ match =>{ #"message" => "%{COMBINEDAPA ...

  4. 当下最流行的微服务与spring cloud,你搞清楚了吗?

    微服务架构:Spring-Cloud 什么是微服务? 微服务就是把原本臃肿的一个项目的所有模块拆分开来并做到互相没有关联,甚至可以不使用同一个数据库. 比 如:项目里面有User模块和Power模块, ...

  5. snort规则中byte_test参数详解

    例子: byte_test:4,>,1000,20 这里是从本规则内前面匹配的位置结尾开始,向后偏移20个字节,再获取后面的4个字节的数据,与十进制数据1000进行比较,如果大于1000,就命中 ...

  6. MyBatis 核心配置综述之 ParameterHandler

    目录 ParameterHandler 简介 ParameterHandler 创建 ParameterHandler 中的参数从何而来 ParameterHandler 解析 MyBatis 四大核 ...

  7. jQuery插件之路(一)——试着给jQuery的一个Carousel插件添加新的功能

    前几日在网上看到了一个关于Carousel插件的教学视频,于是也顺便跟着学习着做了一下.但是在做完之后发现,在别的网站上面看到类似的效果要比现在做的这个要多一个功能,也就是在底下会有一些按钮,当鼠标放 ...

  8. 【Java例题】5.1 多项式计算

    1. 计算下列多项式的值. pn=an*x^n+...+a1*x+a0其中,"^"表示乘方. x.n以及ai(i=0,1,...,n-1)由键盘输入. package chapte ...

  9. 12、面向对象的思想(OOP)

    面向对象与面向过程 1.都是解决问题的思维方式,都是代码的组织的方式: 2.解决简单的问题可以使用面向过程: 3.解决复杂的问题建议使用面向对象,微观处理依旧会使用面向过程. 对象的进化史(数据管理的 ...

  10. 基于Starling的mask实现

    作为一个从c++转过来的程序员,flash原生的自定义mask实在是太好用,能方便实现各种效果,比如新手引导的高亮.viewport效果等.可惜starling的显示对象并不支持mask特性,查阅go ...