ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1083. Factorials!!!

Help ! Why Wrong Answers?
Posted by Yeo Kern Sin 23 Feb 2002 19:33
What could be the problem?  My assumption is when N <= k the answer
is N*N. The rest is normal calculation.  But I always got WRONG
ANSWER !!! Please help !!!

***************************
#include <stdio.h>
#include <stdlib.h>

void main ()
{
 int number, number_of_factoral;
 int total, i, frequency;
 char factor[21];
 div_t result;
 int option;

 scanf("%d %s",&number, factor);

 number_of_factoral = strlen(factor);

 if (number <= number_of_factoral)
 {
        total = number * number;
 }
 else
 {
        result = div(number, number_of_factoral);
        total = number;
        i = 1;

        while ((number - (i * number_of_factoral)) > 0)
        {
                total = total * (number- (i * number_of_factoral));
                i = i + 1;
        }

        if (result.rem > 0)
            total = total * result.rem;
        else
            total = total * number_of_factoral;

 }
 printf("%d\n", total);
}
******************************