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 |
Re:Time Limit ExceedIn Reply To:Time Limit Exceed Posted by:gothree at 2006-11-15 20:39:02 #include<iostream> using namespace std; const int size = 40000; int a[size]; int n; void getPrime(); int solve(); int main() { getPrime(); while ( true ) { cin >> n; if ( n == 0 ) break; cout << solve() << endl; } return 0; } void getPrime() { for ( int i = 2; i < size; i ++) a[i] = 1; for ( int j = 2; j < size; j ++ ) { if (a[j]) for ( int k = j + j; k < size; k += j ) a[ k ] = 0; } } int solve() { int c = 0; for ( int i = 2; i <= n / 2; i ++ ) if ( a[i] && a[ n - i ]) c ++; return c; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator