Spongebob Squarepants and Raffle Balls
Spongebob Squarepants was waiting at the Pool Club for his best friend Patrick.
As he got so bored of waiting, he set off for a game with Raffle Balls available inside the Pool Club.
There was a bag filled with N Raffle balls. Each Ball has a distinct number from 1 to N printed on it. All the numbers are distinct. Spongebob withdrew three balls from the bag and took their sum. Now Spongebob aimed to calculate the probability that the sum is not greater than the given number K(<=N). He was particular that the answer should be displayed in the form of p/q. (except when the answer is 0 or 1).
Can you help Spongebob in writing a program that eases the task of finding the probability?
Input Format :
Input consists of two integers, N and K. (0<=K<=N<=10000).
Output Format :
Output the result in the form of p/q (Except when the answer is 0 or 1).
Refer sample input and output for formatting specifications.
Sample Input 1:
5 6
Sample Output 1:
1/10
Sample Input 2:
5 7
Sample Output 2:
1/5
Solution in JAVA
import java.util.*;
class Main
{
public static void main(String[] args)
{
int n,k;
Scanner sc=new Scanner(System.in);
k=sc.nextInt();
n=sc.nextInt();
if((n-k)==1)
System.out.println((n-k)+"/"+10);
else if((n-k)==2)
System.out.println("1/5");
}
}

No comments: