• 素数问题_算数基本定理


           定理:每个大于1 的正整数n都可以被唯一地写成素数的乘积,在乘积中的素因子按照非降序排列。正整数n的分解式n = p1^a1 * p2^a2****pk^ak 称为n的标准分解式,其中p1, p2, ...pk是素数,p1<p2<....pk, 且a1,a2....ak是正整数。

    性质1:若n的标准素因子分解表达式为上面所述,设d(n)为n的素因子的个数,则 

    d(n) = (a1+1) * (a2+1) * *** (ak + 1).

          性质2:n!的素因子分解中的素数p的幂为[n/p] + [n/p^2] + [n/p^3] + ........

    例题:

    n!后面有多少个0

    Problem : 118

    Time Limit : 1000ms

    Memory Limit : 65536K

    description

    从输入中读取一个数n,求出n!中末尾0的个数。

    input

    输入有若干行。第一行上有一个整数m,指明接下来的数字的个数。然后是m行,每一行包含一个确定的正整数n,1&lt;=n&lt;=1000000000。

    output

    对输入行中的每一个数据n,输出一行,其内容是n!中末尾0的个数。

    sample_input

    3
    3
    100
    1024
    

    sample_output

    0
    24
    253
    

    hint

    source

    #include <iostream>
    #include <cstdio>
    #include <cstdlib>
    #include <cstring>
    #include <algorithm>
    using namespace std;
    
    typedef long long int LL ;
    
    
    int main() {
    	int m;
    	cin >> m;
    	while (m --) {
    		LL n;
    		cin >> n;
    		int num = 5;
    		int res = 0;
    		while (n /num) {
    			res += n/num;
    			num *= 5;
    		}	
    		cout << res << endl;
    	}
    	
    	return 0;
    }


  • 相关阅读:
    python操作Excel读写--使用xlrd
    python 使用pymssql连接sql server数据库
    python pdb调试
    sqlser生成guid与复制造数
    sqlser游标与for循环
    bat写循环
    Jenkins配置多任务
    git命令行与Jenkins
    Jenkins执行python脚本
    Windows环境Jenkins配置免密登录Linux
  • 原文地址:https://www.cnblogs.com/Tovi/p/6194840.html
Copyright © 2020-2023  润新知