LightOJ-1028 Trailing Zeroes (I)---因子数目
题目链接:
https://cn.vjudge.net/problem/LightOJ-1028
题目大意:
一个十进制数1≤n≤1012,现在用base进制来表示,问有多少种表示方法使得最后一位上的数为0?
等同于求出n有多少种约数,即n%base==0;
解题思路:
注意:base进制不可能为1,算出的结果应该减去因子1
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<stack>
#include<map>
#include<sstream>
#define Mem(a, b) memset(a, b, sizeof(a))
using namespace std;
typedef long long ll;
const int INF = 1e9 + ;
const int maxn = +;
int prime[maxn];
bool is_prime[maxn];
int sieve(int n)//返回n以内素数的个数
{
int p = ;
for(int i = ; i <= n; i++)is_prime[i] = ;
is_prime[] = is_prime[] = ;
for(ll i = ; i <= n; i++)
{
if(is_prime[i])
{
prime[p++] = i;
for(ll j = i * i; j <= n; j += i)is_prime[j] = ;//这里涉及i*i,必须使用long long
}
}
return p;
} ll Divisors_num(ll n, int tot)//素数总数
{
ll ans = ;
for(int i = ; i < tot && prime[i] * prime[i] <= n; i++)
{
if(n % prime[i] == )
{
int cnt = ;
while(n % prime[i] == )
{
cnt++;
n /= prime[i];
}
ans *= (cnt + );
}
}
if(n > )ans *= ;
return ans;
}
int main()
{
int T, cases = ;
int tot = sieve();
cin >> T;
while(T--)
{
ll n;
cin >> n;
cout<<"Case "<<++cases<<": "<<Divisors_num(n, tot)-<<endl;
}
return ;
}
LightOJ-1028 Trailing Zeroes (I)---因子数目的更多相关文章
- 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 ...
- LightOJ 1028 - Trailing Zeroes (I) 质因数分解/排列组合
题意:10000组数据 问一个数n[1,1e12] 在k进制下有末尾0的k的个数. 思路:题意很明显,就是求n的因子个数,本来想直接预处理欧拉函数,然后拿它减n就行了.但注意是1e12次方法不可行.而 ...
- LightOJ 1138 Trailing Zeroes (III)(二分 + 思维)
http://lightoj.com/volume_showproblem.php?problem=1138 Trailing Zeroes (III) Time Limit:2000MS M ...
- Light OJ 1028 - Trailing Zeroes (I) (数学-因子个数)
题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1028 题目大意:n除了1有多少个因子(包括他本身) 解题思路:对于n的每个因子 ...
- LightOj 1138 - Trailing Zeroes (III) 阶乘末尾0的个数 & 二分
题目链接:http://lightoj.com/volume_showproblem.php?problem=1138 题意:给你一个数n,然后找个一个最小的数x,使得x!的末尾有n个0:如果没有输出 ...
- Lightoj 1090 - Trailing Zeroes (II)
题目连接: http://www.lightoj.com/volume_showproblem.php?problem=1090 题目大意: 给出n,r,p,q四个数字1<=n,r,p,q< ...
- LightOj 1090 - Trailing Zeroes (II)---求末尾0的个数
题目链接:http://lightoj.com/volume_showproblem.php?problem=1090 题意:给你四个数 n, r, p, q 求C(n, r) * p^q的结果中末尾 ...
- lightoj 1138 - Trailing Zeroes (III)【二分】
题目链接:http://lightoj.com/volume_showproblem.php? problem=1138 题意:问 N. 末尾 0 的个数为 Q 个的数是什么? 解法:二分枚举N,由于 ...
- LightOj 1138 Trailing Zeroes (III)
题目描述: 假设有一个数n,它的阶乘末尾有Q个零,现在给出Q,问n最小为多少? 解题思路: 由于数字末尾的零等于min(因子2的个数,因子5的个数),又因为2<5,那么假设有一无限大的数n,n= ...
随机推荐
- mysql把之前表单进行拆分
今天有个任务是需要把之前的历史数据做一个清理. 原历史数据 很多电话号码是放到了一起.所以需要新建一个联系方式表.然后进行增加 新建表格如下: 然后再进行查询数据. SELECT a.uid,subs ...
- css垂直居中几种方法(二)
方法1:table-cell .box1{ display: table-cell; vertical-align: middle; text-align: center; } <div cla ...
- 问题记录——java.lang.IllegalArgumentException: Illegal character in scheme name at index 0
以下http请求报错是因为,请求的地址前面有个空格.... 2019-01-09 03:30:23,154 ERROR [business.modules.merchantreportresult.s ...
- MySQL误删root用户导致无法登陆解决方法
测试环境 删除前 mysql> select user,host,password from mysql.user; +------+-----------+---------------- ...
- android 学习资源网址
脚本之家: http://www.jb51.net/list/list_233_2.htm csdn: http://blog.csdn.net/xubo578/article/details/571 ...
- 使用params
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...
- 【SoapUI】http接口测试
一.接口介绍 API(Application Programming Interface,应用程序编程接口) 1.硬件接口 USB接口 硬盘接口 SD卡接口 LAN口和WAN口 CONSOLE口 .. ...
- js经验点滴js apply/call/caller/callee/bind使用方法与区别分析
一.call 方法 调用一个对象的一个方法,以另一个对象替换当前对象(其实就是更改对象的内部指针,即改变对象的this指向的内容). Js代码 call([thisObj[,arg1[, arg2[, ...
- avalon实现分页组件
前言 分页组件比较常见,但是用avalon实现的见的不多,这个分页组件,可以适配2种分页方式, 第一种是每次点击下一页,就请求一次后台,并返回当页数据和总条数,我称之为假分页: 第二种是一次性把所有数 ...
- 初学Hadoop之WordCount词频统计
1.WordCount源码 将源码文件WordCount.java放到Hadoop2.6.0文件夹中. import java.io.IOException; import java.util.Str ...