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 ...
随机推荐
- The Little Prince-12/05
The Little Prince-12/05 "When a mystery is too overpowering, one dare not disobey. Absurd as it ...
- priority todo
analyze the work about change to right spindle
- org.springframework.jdbc.UncategorizedSQLException
org.springframework.jdbc.UncategorizedSQLException: StatementCallback; uncategorized SQLException fo ...
- thinkphp 检测验证码
/** * 检测验证码 * @param integer $id 验证码ID * @return boolean 检测结果 */function check_verify($code, $id = 1 ...
- django 把函数装饰器变为方法装饰器
暗暗啊
- spring Boot(十九):使用Spring Boot Actuator监控应用
spring Boot(十九):使用Spring Boot Actuator监控应用 微服务的特点决定了功能模块的部署是分布式的,大部分功能模块都是运行在不同的机器上,彼此通过服务调用进行交互,前后台 ...
- pprof函数名未翻译、为函数地址0x00000232382788
这几天在分析一个性能未达预期的功能,使用gperftools cpu profiler生成后,使用pprof格式化的时候,发现pprof出的结果函数名未翻译.为函数地址,如下所示: 每个节点代表一个函 ...
- CentOS7 彻底关闭 IPV6
查看服务监听的IP中是否有IPv6格式的地址 netstat -tuln 如果有tcp6协议的就是有打开ip6 编辑/etc/default/grub,在GRUB_CMDLINE_LINUX加上的后面 ...
- 在android下使用i2c tools
在android使用i2c tools访问i2c,很方便,可以在https://launchpad.net/ubuntu/+source/i2c-tools 下载最新的i2c tools. 把i2c- ...
- 为什么说 HashMap 是非线程安全的?
我们在学习 HashMap 的时候,都知道 HashMap 是非线程安全的,同时我们知道 HashTable 是线程安全的,因为里面的方法使用了 synchronized 进行同步. 但是 HashM ...