**题意:**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) 质因数分解/排列组合的更多相关文章

  1. POj3421 X-factor Chains(质因数分解+排列组合)

    POj3421X-factor Chains 一开始没读懂题意,不太明白 Xi | Xi+1 where a | b means a perfectly divides into b的意思,后来才发现 ...

  2. 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 ...

  3. Light OJ 1028 - Trailing Zeroes (I) (数学-因子个数)

    题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1028 题目大意:n除了1有多少个因子(包括他本身) 解题思路:对于n的每个因子 ...

  4. LightOJ 1138 Trailing Zeroes (III)(二分 + 思维)

    http://lightoj.com/volume_showproblem.php?problem=1138 Trailing Zeroes (III) Time Limit:2000MS     M ...

  5. LightOJ 1356 Prime Independence(质因数分解+最大独立集+Hopcroft-Carp)

    http://lightoj.com/login_main.php?url=volume_showproblem.php?problem=1356 题意: 给出n个数,问最多能选几个数,使得该集合中的 ...

  6. hdu 4497 GCD and LCM 质因素分解+排列组合or容斥原理

    //昨天把一个i写成1了 然后挂了一下午 首先进行质因数分解g=a1^b1+a2^b2...... l=a1^b1'+a2^b2'.......,然后判断两种不可行情况:1,g的分解式中有l的分解式中 ...

  7. csu 1801(合数分解+排列组合)

    1801: Mr. S’s Romance Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 15  Solved: 5[Submit][Status][W ...

  8. LightOj 1138 - Trailing Zeroes (III) 阶乘末尾0的个数 & 二分

    题目链接:http://lightoj.com/volume_showproblem.php?problem=1138 题意:给你一个数n,然后找个一个最小的数x,使得x!的末尾有n个0:如果没有输出 ...

  9. LightOj 1090 - Trailing Zeroes (II)---求末尾0的个数

    题目链接:http://lightoj.com/volume_showproblem.php?problem=1090 题意:给你四个数 n, r, p, q 求C(n, r) * p^q的结果中末尾 ...

随机推荐

  1. 小程序的picker的range 是一个 Object Array (对象数组)

    小程序的picker的range 是一个 Object Array (对象数组) 数据: array: [{'id':1,'name':'Android'},{'id':2,'name':'IOS'} ...

  2. Thunder团队第一周 - Scrum会议6

    Scrum会议6 小组名称:Thunder 项目名称:爱阅app Scrum Master:苗威 工作照片: 参会成员: 王航:http://www.cnblogs.com/wangh013/ 李传康 ...

  3. Python学习之路5 - 函数

    函数 定义方式: def func(): "这里面写函数的描述" 这里写代码 return x #如果没有返回值就叫"过程",函数和过程的区别就是有无返回值 实 ...

  4. iOS- 如何将非ARC的项目转换成ARC项目(实战)

    1.前言   因为公司有个国外餐饮系统,编程开发了3-4年,之前用的都是非ARC,开发到今年,第一批迭代开发的人员早已不见,目前发现了有许多的内存泄露之类的,系统没有自动释放该释放的内存.一旦app长 ...

  5. mysql的my.cnf配置文件

    [client]port = 3306default-character-set=utf8mb4socket = /var/run/mysqld/mysql.sock# user=david# pas ...

  6. Java字符串2

    if(str!= null && str.isEmpty()){ dao.get(str); } str.isEmpty判断字符串是否为空字符串

  7. react-event-pooling

    react-event-pooling 事件池 https://codesandbox.io/s/3xp4y9zp7q https://reactjs.org/docs/events.html#eve ...

  8. 【Python】PYTHON中STRIP()方法学习笔记

    Python strip() 方法用于移除字符串头尾指定的字符(默认为空格). 当使用strip('xxx'),只要字符串头尾有"xxx"中的一个,就会去掉,而不是符合字符串''x ...

  9. Struts2自定义结果视图(servlet验证码)

    1.编写一个类实现com.opensymphony.xwork2.Result,或者继承org.apache.struts2.dispatcher.StrutsResultSupport 2.自定义的 ...

  10. 按照list中实体类的某一属性排序

    传进一个装有实体类的list public void sort(List<MedicalPracticesDetail> mpdList){ Collections.sort(mpdLis ...