Advertisement
a53

numere27

a53
May 9th, 2019
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.37 KB | None | 0 0
  1. #include <fstream>
  2. using namespace std;
  3. ifstream f("numere.in");
  4. ofstream g ("numere.out");
  5.  
  6. int main()
  7. {
  8. int p,n,x,dif1=20000000,dif2=20000000,y,xx;
  9. long long xmin,xmax,i, nr1,nr2;
  10. unsigned long long nr;
  11. f>>p;
  12. if (p==1)
  13. {
  14. f>>n;
  15. nr=9;
  16. for (i=1; i<=n-3; i++)
  17. nr=nr*5;
  18. g<<nr<<'\n';
  19. }
  20. else
  21. {
  22. f>>x;
  23. y=x;
  24. xmin=163;
  25. xmax=812;
  26. i=3;
  27. while (y>999)
  28. {
  29. i++;
  30. if (i%2==0)
  31. {
  32. xmin=xmin*10;
  33. xmax=xmax*10+9;
  34. }
  35. else
  36. {
  37. xmin=xmin*10+1;
  38. xmax=xmax*10+8;
  39. }
  40. y=y/10;
  41. }
  42. if (x<xmin) g<<xmin;
  43. else
  44. if (x>xmax) g<<xmax;
  45. else
  46. {
  47. for (xx=x-1; xx>=xmin; xx--)
  48. {
  49. int v[11],k=0,n2,i,xxx=xx, bun=1;
  50. while (xxx>99)
  51. {
  52. k++;
  53. v[k]=xxx%10;
  54. xxx=xxx/10;
  55. }
  56. if (xxx!=16 && xxx!=25 && xxx!=36 && xxx!=49 && xxx!=81) bun=0;
  57. else if ((xxx==16|| xxx==36)&& (v[k]!=3 && v[k]!=5 && v[k]!=7)) bun=0;
  58. else if ((xxx==25 || xxx==49 ||xxx==81) && v[k]!=2) bun=0;
  59. else
  60. for (i=k-1; i>=1; i--)
  61. if (v[i]%2==v[i+1]%2) bun=0;
  62. if (bun)
  63. {
  64. nr1=xx;
  65. dif1=x-nr1;
  66. break;
  67. }
  68. }
  69. for (xx=x+1; xx<=xmax; xx++)
  70. {
  71. int v[11],k=0,n2,i,xxx=xx, bun=1;
  72. while (xxx>99)
  73. {
  74. k++;
  75. v[k]=xxx%10;
  76. xxx=xxx/10;
  77. }
  78. if (xxx!=16 && xxx!=25 && xxx!=36 && xxx!=49 && xxx!=81) bun=0;
  79. else if ((xxx==16|| xxx==36)&& (v[k]!=3 && v[k]!=5 && v[k]!=7)) bun=0;
  80. else if ((xxx==25 || xxx==49 ||xxx==81) && v[k]!=2) bun=0;
  81. else
  82. for (i=k-1; i>=1; i--)
  83. if (v[i]%2==v[i+1]%2) bun=0;
  84. if (bun)
  85. {
  86. nr2=xx;
  87. dif2=nr2-x;
  88. break;
  89. }
  90. }
  91. if (dif1<=dif2)
  92. g<<nr1<<'\n';
  93. else
  94. g<<nr2<<'\n';
  95. }
  96. }
  97. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement