Author : Jisan
Programming language : Java
Difficulty : Easy
Status : Accepted
Problem number : UVA-369
http://uva.onlinejudge.org/index.php?option=onlinejudge&page=show_problem&problem=305
Code:
import java.util.Scanner;
public class Uva_369{
public static void main(String args[]){
Scanner in=new Scanner(System.in);
while(in.hasNext()){
long n=in.nextLong();
long r=in.nextLong();
if(n==0 && r==0){
break;
}
System.out.println(n+" things taken "+r+" at a time is "+fact(n,r) +" exactly.");
}
}
public static long fact(long n,long m){
long res=1;
if(n-m<m){
m=n-m;
}
for(long i=1;i<=m;i++,n--){
res=res*n;
res=res/i;
}
return res;
}
}
Programming language : Java
Difficulty : Easy
Status : Accepted
Problem number : UVA-369
http://uva.onlinejudge.org/index.php?option=onlinejudge&page=show_problem&problem=305
Code:
import java.util.Scanner;
public class Uva_369{
public static void main(String args[]){
Scanner in=new Scanner(System.in);
while(in.hasNext()){
long n=in.nextLong();
long r=in.nextLong();
if(n==0 && r==0){
break;
}
System.out.println(n+" things taken "+r+" at a time is "+fact(n,r) +" exactly.");
}
}
public static long fact(long n,long m){
long res=1;
if(n-m<m){
m=n-m;
}
for(long i=1;i<=m;i++,n--){
res=res*n;
res=res/i;
}
return res;
}
}
No comments:
Post a Comment