|  | 
|  | 
| вернуться в форум | why I get crash(access violation) at test 6? why I get crash(access violation) at test 6?who have the test?
 S.O.S!!
Re: why I get crash(access violation) at test 6? Послано Blum  25 ноя 2007 04:4050000 2Re: why I get crash(access violation) at test 6? This is not test 6! The answer of 50000 2 is 3 and my program shows it but i have WA on test 6!!!Re: why I get crash(access violation) at test 6? Lol, the question was asked in 2006, first answer came in 2007 and the second one in 2009 ! vava viva !Re: why I get crash(access violation) at test 6? Delete
 Edited by author 05.04.2010 10:36
 
 Edited by author 05.04.2010 10:36
use legendre formula to count how many times prime contains in n! #include<iostream>using namespace std;
 
 bool prime[50001];
 int primes[6000],len=0;
 int n,m;
 int primesUp[6000];
 int primesDown[6000];
 long long ans = 0;
 
 long long legendre(long long num,long long p){
 long long c = 0;
 long long tmp = p;
 while( (num/p) !=0){
 c+=num/p;
 p*=tmp;
 }
 return c;
 
 }
 int main(){
 #ifndef ONLINE_JUDGE
 freopen("input.txt","r",stdin);
 freopen("output.txt","w",stdout);
 #endif
 
 cin>>n>>m;
 memset(prime,true,sizeof(prime));
 for(int i=2;i<=223;i++){
 if(prime[i]){
 for(int j=i+i;j<=50000;j+=i)
 prime[j] = false;
 }
 }
 for(int i=2;i<=n;i++){
 if(prime[i]){
 primes[len] = i;
 len++;
 }
 }
 for(int i=0;i<len;i++){
 primesUp[i] += legendre(n,primes[i]);
 primesDown[i] += legendre(m,primes[i]);
 primesDown[i] += legendre(n-m,primes[i]);
 }
 for(int i=0;i<len;i++){
 if(primesUp[i] > primesDown[i])
 ans++;
 }
 cout<<ans<<endl;
 return 0;
 }
 | 
 | 
|