标签:math.h stdio.h color i++ include return int bsp div
1 #include<stdio.h> 2 #include<math.h> 3 int main() 4 { 5 int ss(double x); 6 int n,i,s,t,a,b; 7 double m,x,s1,s2; 8 scanf("%d",&n); 9 while(n--) 10 { 11 scanf("%lf",&m); 12 t=ss(m); 13 if(t) 14 if(m==1) 15 printf("2 1\n"); 16 else 17 printf("%.0lf 0\n",m); 18 else 19 { 20 for(i=1; m!=0; i++) 21 { 22 x=m-i; 23 s=ss(x); 24 if(s) 25 break; 26 } 27 a=i;s1=x; 28 for(i=1; m!=0; i++) 29 { 30 x=m+i; 31 s=ss(x); 32 if(s) 33 break; 34 } 35 b=i;s2=x; 36 if(a<=b) 37 printf("%.0lf %d\n",s1,a); 38 else 39 printf("%.0lf %d\n",s2,b); 40 } 41 } 42 return 0; 43 } 44 45 int ss(double x) 46 { 47 int t,i,y,s; 48 y=(int)sqrt(x); 49 s=(int)x; 50 for(i=2,t=1; i<=y; i++) 51 { 52 if(s%i==0) 53 { 54 t=0; 55 break; 56 } 57 } 58 return (t); 59 }
标签:math.h stdio.h color i++ include return int bsp div
原文地址:http://www.cnblogs.com/qq188380780/p/6219714.html