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 |
这题要5000ms干啥??暴力才16ms#include <stdio.h> #include <cmath> bool p(int n){ if(!(n^2))return 1; if(!(n%2))return 0; int q = (int)sqrt(n+0.0); for(int i=3; i<=q;i+=2){ if(!(n%i))return 0; } return 1; } int main() { int n; while(1){ scanf("%d",&n); if(!n)break; if(p(n))printf("0\n"); else{ int s=n-1,x=n+1; for(;!p(s);s--); for(;!p(x);x++); printf("%d\n",x-s); } } return 0; } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator