0% found this document useful (0 votes)
43 views2 pages

Code - UVa 568 - Just The Facts

This document contains source code for a C program that precomputes and stores the last digit of the factorial of numbers up to 10001. The code defines an array to store the precomputed values, includes necessary headers, contains a function to precompute the values by calculating the factorial and storing the last digit of each result, and a main function that takes user input, looks up the precomputed last digit in the array and prints the result.

Uploaded by

Israel Marino
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
43 views2 pages

Code - UVa 568 - Just The Facts

This document contains source code for a C program that precomputes and stores the last digit of the factorial of numbers up to 10001. The code defines an array to store the precomputed values, includes necessary headers, contains a function to precompute the values by calculating the factorial and storing the last digit of each result, and a main function that takes user input, looks up the precomputed last digit in the array and prints the result.

Uploaded by

Israel Marino
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

jjajaallrl hlooihrrx israel

Code

UVa 568 - Just the Facts

/* 568 C "Just the Facts" */

/* @BEGIN_OF_SOURCE_CODE */

#include <stdio.h>

#define FACT_UPTO 10001

int n, fact_lnzd[FACT_UPTO] ;

void precompute(void)
{
int i, fact ;

fact_lnzd[0] = fact_lnzd[1] = fact = 1 ;

for (i=2; i<=FACT_UPTO; i++) {


fact = fact * i ;
while (fact%10==0)
fact /= 10 ;
fact = fact%100000 ;
fact_lnzd[i] = fact%10 ;
}
}

int main()
{
precompute() ;
while (scanf("%d", &n) != EOF)
printf("%5d -> %d\n", n, fact_lnzd[n]) ;
return 0;
}

/* @END_OF_SOURCE_CODE */

Posted by Right now at 3:21 AM


Labels: Ad Hoc, UVaOJ Vol-5

No comments:

Post a Comment

Enter your comment...

Comment as: IsraelMarino (G Sign out

Publish Preview Notify me

Newer jojojo Post Home Older Post

Seguir

Archive

Statistics @felix-halim Hits

4,996

Simple theme. Powered by Blogger.

You might also like