Advertisement
hemel18681

count of divisor of a factorial (also ncr)

Feb 1st, 2020
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. //first we have to find the prime factorization count of that number
  2. //we have to found out count after ncr calculation
  3. //then add 1 with the count
  4. //calculate if need more
  5. #include<stdio.h>
  6. #define ll long long
  7. int prime[90], range=0;
  8. int vis[500];
  9. void inti(){
  10. int i,j;
  11. for(i=2; i*i<=431; i++){
  12. if(vis[i]==0){
  13. for(j=i*i;j<=431;j+=i){
  14. vis[j]=1;
  15. }
  16. }
  17. }
  18. for(i=2;i<=431;i++){
  19. if(vis[i]==0){
  20. //printf("%d\n", i);
  21. prime[range++]=i;
  22. }
  23. }
  24. }
  25.  
  26. int cal(int n, int p){
  27. if(n<p) return 0;
  28. else return(n/p + cal(n/p, p));
  29. }
  30.  
  31. int main(){
  32. //inti();
  33. int n,k,i;
  34. __int64 result =1,pre;
  35. inti();
  36. //printf("%d\n", range);
  37. while(scanf("%d%d",&n,&k)==2){
  38. result=1;
  39. if(k==0||k==n){
  40. printf("1\n");
  41. continue;
  42. }
  43. for(i=0;i<range&&prime[i]<=n;i++){
  44. pre=cal(n,prime[i]) - cal(n-k,prime[i]) - cal(k,prime[i]);
  45. result = result * (pre+1);
  46. }
  47. printf("%I64d\n", result);
  48. }
  49. return 0;
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement