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的结果中末尾 ...
随机推荐
- Thunder团队第五周 - Scrum会议2
Scrum会议2 小组名称:Thunder 项目名称:i阅app Scrum Master:胡佑蓉 工作照片: 参会成员: 王航:http://www.cnblogs.com/wangh013/ 李传 ...
- 测试报告M2
1,项目简介我们已经在第一次测试报告中说过,这一次主要说一下场景测试实例 1.1测试人员 测试人员包括团队开发小组成员以及特邀测试用户组. 1) 团队内部测试主要针对网站支持的各功能组件进行一一测试 ...
- android 出现Make sure the Cursor is initialized correctly before accessing data from it
Make sure the Cursor is initialized correctly before accessing data from it 详细错误是:java.lang.IllegalS ...
- lintcode-185-矩阵的之字型遍历
185-矩阵的之字型遍历 给你一个包含 m x n 个元素的矩阵 (m 行, n 列), 求该矩阵的之字型遍历. 样例 对于如下矩阵: [ [1, 2, 3, 4], [5, 6, 7, 8], [9 ...
- Sqoop 1.4.6 安装配置
配置环境变量 # SQOOP SQOOP_HOME=/home/hadoop/development/src/sqoop-1.4.6-cdh5.6.0 PATH=$PATH:$SQOOP_HOME/b ...
- Visual Studio 数据库架构比较
一.前言 开发的时候在测试服务器上和线网服务器上面都有我们的数据库,当我们在线网上面修改或者新增一些字段后,线网的数据库也需要更新,这个时候根据表的修改记录,然后在线网上面一个一个增加修改很浪费效 ...
- Qt入门实例
一.基于Qt设计师 1.创建一个GUI项目,选择“Qt4 Gui Application”.其中还有Empty Qt4 Project(空的工程),Qt4 Console Applicaiton(基于 ...
- 前端基础:HTML标签(下)
前端基础HTML标签(下) 1.表单 表单的功能主要用于向服务器传输数据,从而实现客户端与Web服务器的交互.表单能够包含input系列标签,比如:文本字段.复选框.单选按钮.提交按钮等:表单还包含t ...
- Dom样式操作-属性操作
1. 对样式进行操作: 1) 以样式(C1,C2等)为最小单位进行修改. className, classList, (以列表形式获得) classList.add("C2"), ...
- POJ1375:Intervals——题解
http://poj.org/problem?id=1375 题目大意:有一盏灯,求每段被圆的投影所覆盖的区间. —————————————————————— 神题,卡精度,尝试用各种方法绕过精度都不 ...