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 ...
随机推荐
- ajax实现图片上传
1.创建formData表单,模拟表单传递数据(formData有兼容性问题) var formData = new FormData();2.获取到相应的元素 var jobName = $(&qu ...
- 计算概论(A)/基础编程练习1(8题)/2:苹果和虫子
#include<stdio.h> #include<math.h> int main() { /* n个苹果 每x小时能吃掉一个苹果 经过y小时 */ float n, x, ...
- 【新架构测试】Fiddler转发数据测试
跨域转发设置: 首先进行设置, AutoResponder--> 选中Enable rules和Unmatched requests passthrough 然后Import...导入fiddl ...
- Python文件读写、StringIO和BytesIO
1 IO的含义 在计算机中,IO是Input/Output的简写,也就是输入和输出. 由于程序和运行时数据是在内存中驻留,由CPU这个超快的计算核心来执行,涉及到数据交换的地方,通常是磁盘.网络等,就 ...
- php 接收blob数据流,base64数据流 转为 blob二进制数据流
php正常接收参数的方式如下:$_GET$_POST$_REQUEST 但是如果跨语言接收请求参数的话,可能会出现一系列的问题,其他语言的http请求可能是基于数据流的概念来传递参数的,如果按照常规处 ...
- Mac配置java运行环境的步骤
官网下载地址:jdk1.8版本的 http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.htm ...
- linux 文件同步
ref: https://www.cnblogs.com/MacoLee/p/5633650.html https://wenda.so.com/q/1505308236213470 http://b ...
- A writer of dictionaries,a harmless druge.
Nine Years for A and B By Christopher Ricks Dr. Johnson was the greatest man who made a dictionary. ...
- topcoder srm 330 div1
problem1 link 直接模拟. import java.util.*; import java.math.*; import static java.lang.Math.*; public c ...
- SQLServer2014 安装错误:等待数据库引擎恢复句柄失败
查了很多资料最后靠百度百科里的一票报道彻底解决困难.在次发表一下以便给后人排忧解难 已下为百度连接 https://jingyan.baidu.com/article/7908e85cb24c19af ...