UVA-568 Just the Facts

来源:互联网 发布:kali linux arp 编辑:程序博客网 时间:2024/06/07 00:52

2016-08-11

UVA - 568 Just the Facts

题目大意:求阶乘的最后一位非零数字。

解题思路:此题可以直接用大数的阶层来得出。

注意:大数阶层得出的顺序是个十百千万。具体算法见博客,“大数阶层”。

#include <iostream>#include <cstdio>#include <cstring>using namespace std;int num[3000];int main() {int n;while ( ~scanf("%d", &n) ) {memset (num, 0, sizeof(num));num[0] = 1;for (int i = 2; i <= n; i++) {int c = 0;for (int j = 0; j < 3000; j++) {int s = num[j] * i + c;num[j] = s % 10;c = s / 10;}}for (int i = 0; i < 3000; i++)if ( num[i] ) {printf("%5d -> %d\n", n, num[i]);break;}}return 0;}


0 0
原创粉丝点击