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. 完美解决windows10磁盘占用100%并出现卡顿、假死无反应

    完美解决windows10磁盘占用100%并出现卡顿.假死无反应 想必大家也跟我一样,自从用win10系统以后经常会出现这种情况:磁盘突然占用100%然后开始出现假死现象,电脑卡住,点击任何软件没反应 ...

  2. <<Modern CMake>> 翻译 2.4 项目目录结构

    <<Modern CMake>> 翻译 2.4 项目目录结构 本节内容有点跑题.但我认为这是一个很好的方法. 我将告诉你如何规划项目的目录. 这是基于惯例,但将帮助您: 轻松阅 ...

  3. Zabbix编译安装(全)

    一.前言 (一).概述 Zabbix是一个基于WEB界面的提供分布式系统监视以及网络监视功能的企业级的开源解决方案,Zabbix能监视各种网络参数,保证服务器系统的安全运营:并提供灵活的通知机制以让系 ...

  4. js 双向绑定数据

    let aaa = []; let bbb = [1,2,3]; let ccc = [0,9,8]; aaa = bbb; //此时aaa与bbb被绑定(aaa指向bbb的指向) ,若使用push则 ...

  5. 万万没想到,JVM内存结构的面试题可以问的这么难?

    在我的博客中,之前有很多文章介绍过JVM内存结构,相信很多看多我文章的朋友对这部分知识都有一定的了解了. 那么,请大家尝试着回答一下以下问题: 1.JVM管理的内存结构是怎样的? 2.不同的虚拟机在实 ...

  6. byte数组和正数BigInteger之间的相互转换

    旧代码 public static void main(String[] args) { SecureRandom random = new SecureRandom(); byte[] key = ...

  7. bio,nio,aio学习

    http://qindongliang.iteye.com/blog/2018539 1 同步 指的是用户进程触发IO操作并等待或者轮询的去查看IO操作是否就绪 自己上街买衣服,自己亲自干这件事,别的 ...

  8. JavaWeb——JSP开发2

    使用JSP+Servlet实现文件的上传和下载功能 1.文件模型 首先是文件本身,这里创建一个类记录文件的名字和内容: public class Attachment { private String ...

  9. mybatis一对多双向映射

    连表查询 select   id  resultType  resultMap resultType和resultMap不能同时使用 association 属性  映射到多对一中的“一”方的“复杂类 ...

  10. 百度Echarts,蚂蚁金服G2,D3三种主流可视化工具对比

    1.百度的Echarts 官网:https://echarts.baidu.com/ 介绍:ECharts,缩写来自Enterprise Charts,是百度推出的一款开源的,商业级数据图表,它最初是 ...