LightOJ 1028 - Trailing Zeroes (I) 质因数分解/排列组合
**题意:**10000组数据 问一个数n[1,1e12] 在k进制下有末尾0的k的个数。
**思路:**题意很明显,就是求n的因子个数,本来想直接预处理欧拉函数,然后拿它减n就行了。但注意是1e12次方法不可行。而一般的求因子显然也太慢,所有要想另一个办法。已知任意数可以分解成几个**质因数幂的乘积**,所以求出n所有的**质因数**和它的**指数**再进行**排列组合**就可以得到答案了。
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <algorithm>
#include <utility>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <stack>
#include <queue>
#define LL long long
#define MMF(x) memset((x),0,sizeof(x))
#define MMI(x) memset((x), INF, sizeof(x))
using namespace std;
const int INF = 0x3f3f3f3f;
const int N = 1e6+2000;
LL pri[N];
LL vis[N];
LL c = 0;
void prime()
{
MMF(vis);
for(LL i = 2; i < N; i++)
{
if(!vis[i])
{
for(LL j = i*i; j < N; j+= i)
vis[j] = 1;
pri[c++] = i;
}
}
}
int main()
{
prime();
int T;
int cnt = 0;
cin >> T;
while(T--)
{
LL n;
scanf("%lld", &n);
LL ans = 1;
for(int i = 0; i < c && pri[i]*pri[i] <= n; i++)
{
int ct = 0;
while(n % pri[i] == 0)
{
ct++;
n /= pri[i];
}
ans *= ct+1;
}
if(n > 1)//减枝后考虑n为质数的情况
ans <<= 1;
printf("Case %d: %lld\n", ++cnt, ans - 1);
}
return 0;
}
//可知任意数可分解成(p1^x)(p2^y)…的形式,所以求解因子只要在x、y、z…间排列组合就可以了
//这题无法直接使用欧拉函数打表,1e12的数据量定会超时
LightOJ 1028 - Trailing Zeroes (I) 质因数分解/排列组合的更多相关文章
- POj3421 X-factor Chains(质因数分解+排列组合)
POj3421X-factor Chains 一开始没读懂题意,不太明白 Xi | Xi+1 where a | b means a perfectly divides into b的意思,后来才发现 ...
- lightoj 1028 - Trailing Zeroes (I)(素数筛)
We know what a base of a number is and what the properties are. For example, we use decimal number s ...
- Light OJ 1028 - Trailing Zeroes (I) (数学-因子个数)
题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1028 题目大意:n除了1有多少个因子(包括他本身) 解题思路:对于n的每个因子 ...
- LightOJ 1138 Trailing Zeroes (III)(二分 + 思维)
http://lightoj.com/volume_showproblem.php?problem=1138 Trailing Zeroes (III) Time Limit:2000MS M ...
- LightOJ 1356 Prime Independence(质因数分解+最大独立集+Hopcroft-Carp)
http://lightoj.com/login_main.php?url=volume_showproblem.php?problem=1356 题意: 给出n个数,问最多能选几个数,使得该集合中的 ...
- hdu 4497 GCD and LCM 质因素分解+排列组合or容斥原理
//昨天把一个i写成1了 然后挂了一下午 首先进行质因数分解g=a1^b1+a2^b2...... l=a1^b1'+a2^b2'.......,然后判断两种不可行情况:1,g的分解式中有l的分解式中 ...
- csu 1801(合数分解+排列组合)
1801: Mr. S’s Romance Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 15 Solved: 5[Submit][Status][W ...
- LightOj 1138 - Trailing Zeroes (III) 阶乘末尾0的个数 & 二分
题目链接:http://lightoj.com/volume_showproblem.php?problem=1138 题意:给你一个数n,然后找个一个最小的数x,使得x!的末尾有n个0:如果没有输出 ...
- LightOj 1090 - Trailing Zeroes (II)---求末尾0的个数
题目链接:http://lightoj.com/volume_showproblem.php?problem=1090 题意:给你四个数 n, r, p, q 求C(n, r) * p^q的结果中末尾 ...
随机推荐
- 什么是Frozen Binary
对于Python来说,你可以将Python的字节码,PVM(也就是解析器),以及需要的相关类库,打包成一个package,这个package实际上是一个二进制可执行文件,这样,用户获取到这个packa ...
- 小茜(xi)的减肥之路
Description 今天,多年未见的小钧和小江在街头偶遇,小江想看看当年那个蠢蠢的小钧有没有变聪明一些,他灵机一动,说:“当初小茜立了个flag,说一定要减肥,她想着第一天跑一米,第二天跑两米,第 ...
- scrapy(1)——scrapy介绍
Scrapy是一个为了爬取网站数据,提取结构性数据而编写的应用框架. 可以应用在包括数据挖掘,信息处理或存储历史数据等一系列的程序中.所谓网络爬虫,就是一个在网上到处或定向抓取数据的程序,当然,这种说 ...
- alpha-4
前言 失心疯病源4 团队代码管理github 站立会议 队名:PMS 530雨勤(组长) 今天完成了那些任务 19:00~21:50 利用背景相减法完成背景构建与更新模块,查找关于blob更多的论文资 ...
- netbeans调试配置
apache端口8050,xdebug端口9000 1.把项目放到apache的htdocs下(一定要放在htdocs上,要么调试的时候xdebug会一直卡在“等待连接中”) 2.把php_xdebu ...
- xpath获取块元素下<br>下的信息
再爬虫取字段的时候遇到一种类似下面的结构: <p> <br> "通用名称:xxxxxx" </p> 用xpath取的方式://p//text() ...
- 【Python】python-内置常量
引言 Python的内置常量不多,只有6个,分别是True.False.None.NotImplemented.Ellipsis.__debug__ 一.True 1.True是bool类型用来表示的 ...
- BZOJ 1211 树的计数(purfer序列)
首先考虑无解的情况, 根据purfer序列,当dee[i]=0并且n!=1的时候,必然无解.否则为1. 且sum(dee[i]-1)!=n-2也必然无解. 剩下的使用排列组合即可推出公式.需要注意的是 ...
- 【bzoj1737】[Usaco2005 jan]Naptime 午睡时间 dp
题目描述 Goneril is a very sleep-deprived cow. Her day is partitioned into N (3 <= N <= 3,830) equ ...
- 转:Conjugate prior-共轭先验的解释
Conjugate prior-共轭先验的解释 原文:http://blog.csdn.net/polly_yang/article/details/8250161 一 问题来源: 看PRML第 ...