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

[JAVA] Why is it CRASH ? :(
Posted by icytwister 5 Jun 2012 18:12
import java.util.*;
public class MyFact
{
    int factorial(int n,int k)
    {
        int res;
        if(n==1) return 1;
        else if((n-1)%k!=0) return 1;

        res=factorial(n-k,k)*n;
        return res;

    }


    public static void main(String [] args)
    {
        int fact=1;

        MyFact f=new MyFact();

        Scanner in=new Scanner(System.in);
        int n=in.nextInt();

        int k=in.nextInt();
        System.out.print(+f.factorial(n,k));
    }
}

Edited by author 05.06.2012 18:20
Re: [JAVA] Why is it CRASH ? :(
Posted by Smilodon_am [Obninsk INPE] 7 Jun 2012 13:04
Read the input data format carefully! An integer number "k" does not follow after integer number n. Input format example:
9 !!

You should count number of exclamation marks (!).