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= ...
随机推荐
- 从零开始学Linux(11)--more
more命令,是将文件的内容从上到下显示在屏幕上. more会以一页一页的显示方便使用者逐页阅读,而最基本的指令就是按空格键(space)就往下一页显示,按 b 键就会往回(back)一页显示,而且还 ...
- PIXI 根据点走地图(8)
先了解下数学公式例如: 图已知:a.b两点的坐标, c到a的距离d .求c点的坐标. 求 cy 可以根据d / a到b距离 = a到c垂直距离 / a 到 b的垂直距离. 首先求a到b的距离 ...
- Linux-Xshell5
Linux-Xshell5 1.下载 2.安装 3.新建会话(连接) 点击新建 需要知道要连接的 IP, 查看命令 ifconfig 配置 名称可以自己命名,主机写要连接的 IP,其他的不能改 输 ...
- svn server配置与TortoiseSVN、Ankhsvn+VS使用
Svn服务器与客户端安装 1. 下载安装VisualSvn-Server服务端.(过程略)http://subversion.apache.org/packages.html 2. ...
- HTML盒子尺寸的计算
参考链接http://edu.51cto.com/lesson/id-54739.html
- jQuery遍历祖先元素:parentsUntil
Description: Get the ancestors of each element in the current set of matched elements, up to but not ...
- 【c#文档】在 C# 中,(int) ,Int32.Parse() 和 Convert.toInt32() 三种方法的区别
[c#文档]https://msdn.microsoft.com/zh-cn/library/system.convert.toint32.aspx 转载自:http://www.cnblogs.co ...
- js 常用事件句柄总结
HTML 4.0 的新特性之一是有能力使 HTML 事件触发浏览器中的动作(action),比如当用户点击某个 HTML 元素时启动一段 JavaScript.下面是一个属性列表,这些属性可插入 HT ...
- sql 行列转换
create table #test1(id int,name varchar(20), Q1 int, Q2 int, Q3 int, Q4 int) insert into #test1 valu ...
- mysql多表条件更新
有两张表bas_student.bas_householder, 去除学生表中与家长表重复的手机号 UPDATE bas_student a,bas_householder b SET a.mobil ...