Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
为何这个程序过了?但是下面那个TLE?不理解,希望有牛给个解释#include <iostream> using namespace std; #define MAX 220 #define MAXP (2*MAX+1) __int64 n,k; int primes[MAXP],isprime[MAXP]; __int64 dp[440][440]; int factpow(int n,int p) { int d=0; do { n /= p; d += n; }while(n); return d; } __int64 set(__int64 n, __int64 k){ if(dp[n][k]!=-1) return dp[n][k]; dp[n][k]=factpow (n,k); return dp[n][k]; } __int64 ndivs(int n,int k) { int i,ad; __int64 nd=1; for(i = 0; primes[i] <= n; i++) { ad = set(n,primes[i]) - set(k, primes[i]) - set(n-k,primes[i]); nd *= (ad + 1); } return nd; } int main() { //freopen("test.txt","r",stdin); int n,k,i,j; isprime[1]=1; for(i=0;i<432;i++){ for(j=0;j<432;j++){ dp[i][j]=-1; } } n = 0; for(i = 2;i < MAXP; i++) if(!isprime[i]) { primes[n++] = i; for(j = 2 * i; j < MAXP; j += i) isprime[j] = 1; } while(scanf("%d%d",&n,&k)==2) { printf("%I64d\n",ndivs(n,k)); } return 0; } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator