LightOJ - 1138 (二分+阶乘分解)】的更多相关文章

题意:求阶乘尾部有Q(1 ≤ Q ≤ 108)个0的最小N 分析:如果给出N,然后求N!尾部0的个数的话,直接对N除5分解即可(因为尾部0肯定是由5*2构成,那么而在阶乘种,2的因子个数要比5少,所以求阶乘中因子5的个数就是尾部0的个数).本题是给出尾部0的个数,逆推N.如果从小到大枚举的话,肯定会超时. 一般这种问题,可以用二分的方法搜答案.得到答案之后再向下逼近. #include<iostream> #include<algorithm> #include<stdio.…
Time Limit: 2 second(s) Memory Limit: 32 MB You task is to find minimal natural number N, so that N! contains exactly Q zeroes on the trail in decimal notation. As you know N! = 1*2*...*N. For example, 5! = 120, 120 contains one zero on the trail. In…
1138 - Trailing Zeroes (III)   PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 32 MB You task is to find minimal natural number N, so that N! contains exactly Q zeroes on the trail in decimal notation. As you know N! = 1*2*...*N.…
http://lightoj.com/volume_showproblem.php?problem=1138 Trailing Zeroes (III) Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu Submit Status Practice LightOJ 1138 Description You task is to find minimal natural number N, so t…
/* 要求出[1,R]之间的质数会超时,但是要判断[L,R]之间的数是否是素数却不用筛到R 因为要一个合数n的最大质因子不会超过sqrt(n) 所以只要将[2,sqrt(R)]之间的素数筛出来,再用这些素数去筛[L,R]之间的合数即可 */ #include<iostream> #include<cstring> #include<cstdio> #include<cmath> using namespace std; #define ll long lon…
给定两个数m,n,其中m是一个素数. 将n(0<=n<=10000)的阶乘分解质因数,求其中有多少个m. 输入 第一行是一个整数s(0<s<=100),表示测试数据的组数 随后的s行, 每行有两个整数n,m. 输出 输出m的个数. 样例输入 100 5 16 2 样例输出 /*给定两个数m,n 求m!分解质因数后因子n的个数. 这道题涉及到了大数问题,如果相乘直接求的话会超出数据类型的范围. 下面给出一种效率比较高的算法,我们一步一步来. m!=1*2*3*……*(m-2)*(m-…
题目大意 求方程$$\frac{1}{x}+\frac{1}{y}=\frac{1}{N!}$$的正整数解的组数. 思路 咱们把式子整理得$$xy-(x+y)N!=0$$.$xy$和$x+y$?貌似可以因式分解?!于是$$N!^2 - (x + y)N! + xy = N!^2$$,即$$(x-N!)(y-N!)=N!^2$$.令$A=x-N!,B=y-N!$,则原式变为$$A*B=(N!)^2$$.因此,解的个数便是$N!^2$的因子的个数.根据唯一分解定理,任意的正整数都可分解为$\prod…
题目链接:http://lightoj.com/volume_showproblem.php?problem=1138 题意:给你一个数n,然后找个一个最小的数x,使得x!的末尾有n个0:如果没有输出impossible 可以用二分求结果,重点是求一个数的阶乘中末尾含有0的个数,一定和因子5和2的个数有关,因子为2的明显比5多,所以我们只需要求一个数的阶乘的因子中一共有多少个5即可; LL Find(LL x) { LL ans = ; while(x) { ans += x/; x /= ;…
1138 - Trailing Zeroes (III) PDF (English) problem=1138" style="color:rgb(79,107,114)">Statistics Forum Time Limit: 2 second(s) Memory Limit: 32 MB You task is to find minimal natural number N, so that N! contains exactly Q zeroes on the…
http://www.lightoj.com/volume_showproblem.php?problem=1340 题意:问n!在b进制下至少有t个后缀零,求最大的b. 思路:很容易想到一个数通过分解素因子可以得到最大的指数.那么问题关键在于求得n!的素因子的指数,找到指数大于t的所有素因子,再将那些指数除去t,剩下的数就是最大的b了.分解阶乘时,对n不断除素数p,直到n为0时,此时商的和即该素因子的指数. /** @Date : 2016-11-30-19.35 * @Author : Lw…