fork download
  1. #include <stdio.h>
  2.  
  3. int rev(int n) {
  4. int dig,rev=0;
  5. while(n>0)
  6. {
  7. dig=n%10;
  8. rev=rev*10+dig;
  9. n/=10;
  10. }
  11. return rev;
  12. }
  13.  
  14. int bins(int pr[],int e) {
  15. int start=0,end=113,mid,flag=0;
  16. while(start<end) {
  17. mid=(start+end)/2;
  18. if(e>pr[mid]) {
  19. start=mid+1;
  20. printf("l");
  21. } else if(e<pr[mid]) {
  22. end=mid-1;
  23. printf("o");
  24. } else if(e==pr[mid]) {
  25. flag=1;
  26. break;
  27. }
  28. }
  29. if (flag==1)
  30. return mid;
  31. else
  32. return 0;
  33. }
  34.  
  35. int main() {
  36. int j,i,N,revn,count,pr[]={2,3,5,7,11,101,131,151,181,
  37. 191,313,353,373,383,727,757,787,797,919,
  38. 929,10301,10501,10601,11311,11411,12421,12721,12821,13331,
  39. 13831,13931,14341,14741,15451,15551,16061,16361,16561,16661,
  40. 17471,17971,18181,18481,19391,19891,19991,30103,30203,30403,
  41. 30703,30803,31013,31513,32323,32423,33533,34543,34843,35053,
  42. 35153,35353,35753,36263,36563,37273,37573,38083,38183,38783,
  43. 39293,70207,70507,70607,71317,71917,72227,72727,73037,73237,
  44. 73637,74047,74747,75557,76367,76667,77377,77477,77977,78487,
  45. 78787,78887,79397,79697,79997,90709,91019,93139,93239,93739,
  46. 94049,94349,94649,94849,94949,95959,96269,96469,96769,97379,
  47. 97579,97879,98389,98689,1003001};
  48.  
  49. scanf("%d",&N);
  50. if(N%2==0)
  51. N--;
  52. for(i=N;;i+=2) {
  53. revn=rev(i);
  54. if(i==revn) {
  55. printf("\n%d",revn);
  56. count=bins(pr,i);
  57. if(count!=0)
  58. break;
  59. }
  60. }
  61. printf("\n%d",i);
  62. return 0;
  63. }
Success #stdin #stdout 0.01s 2684KB
stdin
4
stdout
3oooool
5oooo
5