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!!!

WA test 10
Posted by Rustam 8 Jun 2007 19:56
I can't understand why wrong answer in test 10
here is my code


#include <iostream>
using namespace std;
int main()
{
    long int i=2,j,k,n,s=1;
    char a[100];
    cin>>n;
    cin>>a;
    k=strlen(a);
    if(n%k)
    {
        j=n-k;
        s=n;
        while(j>=(n%k))
        {
            s*=j;
            j=n-(i++)*k;
        }
        s*=n%k;
    }
    if(n%k==0)
    {
        j=n-k;
        s=n;
        while(j)
        {
            s*=j;
            j=n-(i++)*k;
        }
    }
    if(n<=k) s=n;
    return 0;
}
Use Greater Data Type
Posted by snowfly 13 Jul 2009 19:47
use unsigned __int64:
My AC Code,Neat:)

#include<iostream>
#include<string>
using namespace std;
int main (void){
    int n,k;
    string s;
    cin>>n>>s;
    k=s.size();
    unsigned __int64 fac=1;
    while (n>0){
        fac*=n;
        n-=k;
    }
    cout<<fac<<endl;
    return 0;
}

Edited by author 13.07.2009 19:48

Edited by author 13.07.2009 19:48

Edited by author 13.07.2009 19:48

Edited by author 13.07.2009 19:48