Trailing Zeroes (I) LightOJ - 1028
题意就是给你一个数让你找它的正因子个数(包括自身,不包括1),这个地方用到一个公式,如果不用的话按正常思路来写会TL什么的反正就是不容易写对。
求任意一个大于1的整数的正因子个数
首先任意一个数n,n=P1^a1 * P2^a2 * P3^a3 *……Pn^an;
任意的整数n可以分解为m个素数ai次幂的连续乘机,这个地方解释不清自己再理解一下(Pi都为素数,依次往后pi越来越大,ai就是次幂,自己可以找几个任意整数n来套一下这个公式就会明白了)
然后正因子个数和:sum=(1+a1)*(1+a2)*(1+a3)……*(1+an);
用这两个公式本题就可以轻松解决啦(这里还是不清楚的就套几个数就理解这两个公式了,是完全正确的哦);
AC代码如下:
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
using namespace std;
int pri[];
int tt[];
int s=;
void dabiao() //打个素数表会节省很多时间
{ int j;
memset(tt,,sizeof(tt));
tt[]=;
tt[]=;
for(int i=;i<=;i++)
{
if(tt[i]!=)
{
pri[s++]=i;
for(j=i+i;j<=;j+=i)
tt[j]=;
}
}
return ;
}
int main()
{
int m,i,j,k,t,cas=;
long long n,num,ans;
scanf("%d",&t);
dabiao();
while(t--)
{
scanf("%lld",&n);
num=;
for(i=;i<s&&pri[i]*pri[i]<=n;i++)
{
ans=;
if(n%pri[i]==)
{ while(n%pri[i]==)//此处就是来找素数的N次幂,存起来相乘来计算SUM
{
ans++;
n/=pri[i];
} }
num=num*(ans+);
}
if(n>)//这个地方就不解释啦,自己想想咯
num*=;
printf("Case %d: %lld\n",++cas,num-);
}
return ;
}
Trailing Zeroes (I) LightOJ - 1028的更多相关文章
- Trailing Zeroes (I) LightOJ - 1028(求因子个数)
题意: 给出一个N 求N有多少个别的进制的数有后导零 解析: 对于一个别的进制的数要转化为10进制 (我们暂且只分析二进制就好啦) An * 2^(n-1) + An-1 * 2^(n-2) + `` ...
- Trailing Zeroes (III)(lightoj 二分好题)
1138 - Trailing Zeroes (III) PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: ...
- Trailing Zeroes (III) LightOJ - 1138(二分)
You task is to find minimal natural number N, so that N! contains exactly Q zeroes on the trail in d ...
- Trailing Zeroes (III) LightOJ - 1138 二分+找规律
Time Limit: 2 second(s) Memory Limit: 32 MB You task is to find minimal natural number N, so that N! ...
- Trailing Zeroes (II) LightOJ - 1090(预处理+前缀和)
求C(n,r)*p^q的后缀零 考虑一下 是不是就是求 10^k*m 的k的最大值 而10又是由2 和 5 组成 所以即是求 2^k1 * 5^k2 * m1 中k1和k2小的那一个数 短板效应嘛 ...
- Trailing Zeroes (III) LightOJ - 1138 不找规律-理智推断-二分
其实有几个尾零代表10的几次方但是10=2*510^n=2^n*5^n2增长的远比5快,所以只用考虑N!中有几个5就行了 代码看别人的: https://blog.csdn.net/qq_422797 ...
- LightOJ 1138 Trailing Zeroes (III)(二分 + 思维)
http://lightoj.com/volume_showproblem.php?problem=1138 Trailing Zeroes (III) Time Limit:2000MS M ...
- LightOJ Trailing Zeroes (III) 1138【二分搜索+阶乘分解】
1138 - Trailing Zeroes (III) PDF (English) problem=1138" style="color:rgb(79,107,114)" ...
- Trailing Zeroes (III) -;lightoj 1138
Trailing Zeroes (III) PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 32 MB Y ...
随机推荐
- Python Selenium element is not reachable by keyboard
碰到这个问题,没法解决, 最后这么搞的 pcAction.move_by_offset(571, 534).click().perform() #激活输入框 driver.switch_to.acti ...
- Python基本数据类型——字典
字典 dict 字典是Python的另一种有序的可变数据结构,且可存储任意类型对象. 字典是一种键值对的数据容器,每个键值(key:value)对用冒号(:)分割,每个对之间用逗号(,)分割,整个字典 ...
- fjwc2019 D2T3 排序(堆)
#183. 「2019冬令营提高组」排序 贴一段ppt 考虑模拟出这个算法进行k轮(即外层的i循环到k)时的序列,之后再暴力模拟零散的步. 考虑这个算法在01序列上的表现,k轮后实际上就是将最开始的不 ...
- Java线程安全容器
一.Java同步容器 同步容器是用来解决并发情况下的容器线程安全问题的.给多线程环境准备一个线程安全的容器对象. 线程安全的容器对象: Vector, Hashtable.线程安全容器对象,都是使用s ...
- vertica导出导入数据
直接开. 导出dat vsql -U dbadmin -wlizhenghua -At -F'|' -c "select * from APP_INTER_BOSS_CDR_COUNT_T& ...
- [c/c++] programming之路(4)、常量和变量
一.打开多个程序(温习) #include<stdio.h> #include<stdlib.h> void main(){ ; ]; scanf("%d" ...
- 在android下使用i2c tools
在android使用i2c tools访问i2c,很方便,可以在https://launchpad.net/ubuntu/+source/i2c-tools 下载最新的i2c tools. 把i2c- ...
- Spring 学习——Spring JSR注解——@Resoure、@PostConstruct、@PreDestroy、@Inject、@Named
JSR 定义:JSR是Java Specification Requests的缩写,意思是Java 规范提案.是指向JCP(Java Community Process)提出新增一个标准化技术规范的正 ...
- 网络存储结构简明分析—DAS、NAS和SAN 三者区别
存储的总体分类 主流存储结构 网络存储结构大致分为三种:直连式存储(DAS:Direct Attached Storage).存储区域网络(SAN:Storage Area Network ...
- Ground Defense【不知道叫啥可能就是枚举】
问题 G: Ground Defense 时间限制: 1 Sec 内存限制: 128 MB 提交: 116 解决: 22 [提交] [状态] [命题人:admin] 题目描述 You are a ...