fork download
  1. import java.util.*;
  2. import java.lang.*;
  3. import java.io.*;
  4.  
  5. class Ideone
  6. {
  7. static int mod=10000007;
  8. static int max=10000;
  9. static long fact[]=new long[max+1];
  10. static long ifact[]=new long[max+1];
  11.  
  12. static long power(long base,int exp,int mod)
  13. {
  14. long result=1;
  15. while(exp>0)
  16. {
  17. if(exp%2==1)
  18. result=(result*base)%mod;
  19. base=(base*base)%mod;
  20. exp/=2;
  21. }
  22. return result;
  23. }
  24.  
  25. public static void factorial()
  26. {
  27. fact[0]=1L;
  28. for(int i=1;i<=max;i++)
  29. {
  30. fact[i]=(fact[i-1]*i)%mod;
  31. }
  32. ifact[0]=1L;
  33. ifact[max]=power(fact[max],mod-2,mod);
  34. for(int i=max-1;i>=1;i--)
  35. ifact[i]=(ifact[i+1]*(i+1))%mod;
  36. }
  37.  
  38. static long ncr(int n,int r)
  39. {
  40. if(n<r||r<0)return 0;
  41. long res=fact[n];
  42. res=(res*ifact[r])%mod;
  43. res=(res*ifact[n-r])%mod;
  44. return res;
  45. }
  46.  
  47. public static void main(String[] args)throws java.lang.Exception
  48. {
  49. factorial();
  50. Scanner sc=new Scanner(System.in);
  51. int n=sc.nextInt();
  52. int r=sc.nextInt();
  53. long ans=ncr(n,r);
  54. System.out.println(ans);
  55. }
  56. }
Success #stdin #stdout 0.14s 58696KB
stdin
10 5
stdout
1359745