Trailing Zeroes (I) LightOJ - 1028(求因子个数)
题意:
给出一个N 求N有多少个别的进制的数有后导零
解析:
对于一个别的进制的数要转化为10进制 (我们暂且只分析二进制就好啦)
An * 2^(n-1) + An-1 * 2^(n-2) + ``````+ A1 * 2^1 + A0 * 2^0 = N
因为有后导零 我们暂且只看有一个后导零的情况 即A0 = 0
那么 2 * ( An * 2^(n-2) + An01 * 2^(n-3) + `````` + A1) = N
即 An * 2^(n-2) + An-1 * 2^(n-3) + `````` + A1 = N/2
把2替换为x进制 且 左边设为M
则 M = N / x
所以M的个数即为N的因子的个数
用算术基本定理求因子个数即可

最后还要减1呀!
懒得打代码了。。。。代码原文地址:https://blog.csdn.net/zyz_3_14159/article/details/52824900
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<string>
using namespace std;
typedef long long ll;
bool vis[];
int prime[],cnt;
void getprime()
{
cnt=;
int i,j;
for(i=;i<=;i++)
{
if(!vis[i])
prime[cnt++]=i;
for(j=*i;j<=;j+=i)
vis[j]=;
}
}
ll fun(ll n)
{
ll ans=;
int num,i;
for(i=;i<cnt&&prime[i]*prime[i]<=n;i++)
{
if(n%prime[i]==)
{
num=;
while(n%prime[i]==)
{
num++;
n/=prime[i];
}
ans*=(num+);
}
}
if(n>)
ans*=;
return ans-;
}
int main()
{
int cas,c;
ll n;
getprime();
scanf("%d",&cas);
for(c=;c<=cas;c++)
{
scanf("%lld",&n);
if(n!=)
printf("Case %d: %lld\n",c,fun(n));
else
printf("Case %d: 0\n",c);
}
return ;
}
Trailing Zeroes (I) LightOJ - 1028(求因子个数)的更多相关文章
- Trailing Zeroes (I) LightOJ - 1028
题意就是给你一个数让你找它的正因子个数(包括自身,不包括1),这个地方用到一个公式,如果不用的话按正常思路来写会TL什么的反正就是不容易写对. 求任意一个大于1的整数的正因子个数 首先任意一个数n,n ...
- LightOj1028 - Trailing Zeroes (I)---求因子个数
题目链接:http://lightoj.com/volume_showproblem.php?problem=1028 题意:给你一个数 n (1<=n<=10^12), 然后我们可以把它 ...
- LightOj 1138 - Trailing Zeroes (III) 阶乘末尾0的个数 & 二分
题目链接:http://lightoj.com/volume_showproblem.php?problem=1138 题意:给你一个数n,然后找个一个最小的数x,使得x!的末尾有n个0:如果没有输出 ...
- 172. Factorial Trailing Zeroes(阶乘中0的个数 数学题)
Given an integer n, return the number of trailing zeroes in n!. Example 1: Input: 3 Output: 0 Explan ...
- POJ 2992 Divisors (求因子个数)
题意:给n和k,求组合C(n,k)的因子个数. 这道题,若一开始先预处理出C[i][j]的大小,再按普通方法枚举2~sqrt(C[i][j])来求解对应的因子个数,会TLE.所以得用别的方法. 在说方 ...
- Trailing Zeroes (III)(lightoj 二分好题)
1138 - Trailing Zeroes (III) PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: ...
- Almost All Divisors(求因子个数及思维)
---恢复内容开始--- We guessed some integer number xx. You are given a list of almost all its divisors. Alm ...
- ✡ leetcode 172. Factorial Trailing Zeroes 阶乘中的结尾0个数--------- java
Given an integer n, return the number of trailing zeroes in n!. Note: Your solution should be in log ...
- Easy Number Challenge(暴力,求因子个数)
Easy Number Challenge Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I ...
随机推荐
- Linux(centos7)之更换安装python3(二)
Linux不比window好安装python,折腾了好久,终于成功安装上了python,window上一个安装包完事,可惜Linux上python版本太低不好使,还要更换为3版本,百度了好久,教程上总 ...
- linux centos7 nginx 安装部署和配置
1/什么是NginxNginx("enginex")是一个高性能的HTTP和反向代理服务器,也是一个IMAP/POP3/SMTP代理服务器,在高连接并发的情况下Nginx是Apac ...
- Git报错:Your branch is ahead of 'origin/master' by 1 commit
. commit之后,用git status,打印信息为: # On branch master # Your branch is ahead of 'origin/master' by 1 c ...
- 使用Amplify Shader Editor优化特效Shader
ASE相对于Shader Forge生成的代码更加干净, 用于制作特效的再合适不过,以下是使用ASE优化一个SF制作特效的经过: ## 分析美术用SF制作的Shader 懒得装SF, 直接分析代码可知 ...
- 简介几种系统调用函数:write、read、open、close、ioctl
在 Linux 中,一切(或几乎一切)都是文件,因此,文件操作在 Linux 中是十分重要的,为此,Linux 系统直接提供了一些函数用于对文件和设备进行访问和控制,这些函数被称为系统调用(sysca ...
- 基于Python的信用评分卡模型分析(一)
信用风险计量体系包括主体评级模型和债项评级两部分.主体评级和债项评级均有一系列评级模型组成,其中主体评级模型可用“四张卡”来表示,分别是A卡.B卡.C卡和F卡:债项评级模型通常按照主体的融资用途,分为 ...
- [Notice]博客地址转移 vitostack.com
个人博客地址转移至vitostack.com 这里可能不会经常更新. 欢迎访问新地址.
- vue入门之单文件组件
介绍 在很多 Vue 项目中,我们使用 Vue.component 来定义全局组件,紧接着用 new Vue({ el: '#container '}) 在每个页面内指定一个容器元素. 这种方式在很多 ...
- IDEA下载插件超时的原因
setting中红框的对勾去掉就可以下载插件了
- Gogoing的NABCD
特点之一:路线推荐 N 用户出行需要一个合理的路线计划 A 运用百度地图,还有根据自己的所想去的地方,推荐最省时间,最省钱的路线安排 B 方便用户出行,节约时间,节约金钱 C 对于旅行方面的App, ...