随笔分类 -  阶乘问题

Find the sum of digits in n!
摘要:Find the sum of digits in n!Time Limit:2000MSMemory Limit:65535KBSubmissions:192Accepted:41Descriptionn! meansn*(n1) *... *3 *2 *1Find the sum of the digits in the number n!Inputone line: n (1<n<=10000)Outputthe sum of the digits in the number n!Sample Input10Sample Output27Hint10! =36288003+6 阅读全文

posted @ 2012-05-22 19:20 即为将军 阅读(342) 评论(0) 推荐(0)

N!
摘要:N!Time Limit:5000MSMemory Limit:65535KBSubmissions:96Accepted:26DescriptionGiven an integer N(0 ≤ N ≤ 10000), your task is to calculate N! InputOne N in one line, process to the end of file.OutputFor each N, output N! in one line.Sample Input123Sample Output126解法一://用大整数想乘的方法# include<iostream> 阅读全文

posted @ 2012-05-22 18:57 即为将军 阅读(260) 评论(0) 推荐(0)

N!最右边的非零位的值
摘要:阶乘问题Time Limit: 5000MS Memory Limit: 65535KB Submissions: 348 Accepted: 37 Description 也许你早就知道阶乘的含义,N阶乘是由1到N相乘而产生,如:12! = 1 x 2 x 3 x 4 x 5 x 6 x 7 x 8 x 9 x 10 x 11 x 12 = 479,001,60012的阶乘最右边的非零位为6。写一个程序,计算N(1<=N<=50,000,000)阶乘的最右边的非零位的值。注意:10,000,000!有2499999个零。 Input仅一行包含一个正整数N。 Output单独一行包 阅读全文

posted @ 2012-05-09 10:20 即为将军 阅读(2067) 评论(0) 推荐(0)

N!末尾有多少个0
摘要:给定一个整数N,那么N的阶乘N!末尾有多少个0呢?例如:N=10,N!=3 628 800,N!的末尾有两个0。分析:对N!进行质因数分解,N!=(2^x)×(3^y)×(5^z)…,由于10 = 2×5,所以M只跟X和Z相关,每一对2和5相乘可以得到一个10,于是M = min(X, Z)。不难看出X大于等于Z,因为能被2整除的数出现的频率比能被5整除的数高得多,所以把公式简化为M = Z【解法一:分析后①】#include<iostream>using namespace std;int main(){ int n; int num,p; n = 阅读全文

posted @ 2012-05-09 09:30 即为将军 阅读(2358) 评论(0) 推荐(0)

导航