1 //Accepted 168 KB 969 ms 2 //n!中含有质因数p的个数为t=n/p+n/p^2+n/p^3+... 3 #include <cstdio> 4 #include <cstring> 5 #include <iostream> 6 using namespace std; 7 const int imax_n = 435; 8 int pri[imax_n]; 9 void prime() 10 { 11 for (int i=2;i<imax_n;i++) 12 { 13 for (int j=i*i;j<imax_n;j+=i) 14 { 15 pri[j]=1; 16 } 17 } 18 } 19 int getNumber(int n,int k) 20 { 21 int ans=0; 22 while (n>0) 23 { 24 ans+=n/k; 25 n=n/k; 26 } 27 return ans; 28 } 29 void slove(int n,int k) 30 { 31 __int64 ans=1; 32 for (int i=2;i<=n;i++) 33 if (pri[i]==0) 34 { 35 int t=getNumber(n,i)-getNumber(k,i)-getNumber(n-k,i)+1; 36 ans*=t; 37 } 38 printf("%I64d\n",ans); 39 } 40 int main() 41 { 42 prime(); 43 int n,k; 44 while (scanf("%d%d",&n,&k)!=EOF) 45 { 46 slove(n,k); 47 } 48 return 0; 49 }
1 //Accepted 900 KB 344 ms 2 #include <cstdio> 3 #include <cstring> 4 #include <iostream> 5 using namespace std; 6 const int imax_n = 435; 7 int pri[imax_n]; 8 int a[imax_n][imax_n]; 9 void prime() 10 { 11 for (int i=2;i<imax_n;i++) 12 { 13 for (int j=i*i;j<imax_n;j+=i) 14 { 15 pri[j]=1; 16 } 17 } 18 } 19 int getNumber(int n,int k) 20 { 21 int ans=0; 22 while (n>0) 23 { 24 ans+=n/k; 25 n=n/k; 26 } 27 return ans; 28 } 29 void getA() 30 { 31 for (int i=0;i<=431;i++) 32 { 33 for (int j=2;j<=431;j++) 34 { 35 if (pri[j]==0) 36 a[i][j]=getNumber(i,j); 37 } 38 } 39 } 40 void slove(int n,int k) 41 { 42 __int64 ans=1; 43 for (int i=2;i<=n;i++) 44 if (pri[i]==0) 45 { 46 //printf("a[%d][%d]=%d\n",n,i,a[n][i]); 47 //printf("a[%d][%d]=%d\n",k,i,a[k][i]); 48 //printf("a[%d][%d]=%d\n",n-k,i,a[n-k][i]); 49 int t=a[n][i]-a[k][i]-a[n-k][i]+1; 50 ans*=t; 51 } 52 printf("%I64d\n",ans); 53 } 54 int main() 55 { 56 prime(); 57 getA(); 58 int n,k; 59 while (scanf("%d%d",&n,&k)!=EOF) 60 { 61 slove(n,k); 62 } 63 return 0; 64 }
时间: 2024-10-19 08:56:22