Korotkodul

Блок-схемы

Nov 22nd, 2021 (edited)
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.69 KB | None | 0 0
  1. /******************************************************************************
  2.  
  3. Online C++ Compiler.
  4. Code, Compile, Run and Debug C++ program online.
  5. Write your code in this editor and press "Run" button to compile and execute it.
  6.  
  7. *******************************************************************************/
  8.  
  9. #include <iostream>
  10. #include <cmath>
  11. using namespace std;
  12. using ll = long long;
  13. ll a,b;
  14.  
  15. ll S(ll x){
  16. return (2*3 + 3 * (x - 1)) * x / 2;
  17. }
  18.  
  19.  
  20.  
  21. bool f(ll N){
  22. ll c1 = 0;
  23. bool can = 1;
  24. if (N == 0){
  25. c1 = 0;
  26. }
  27. else{
  28. while (true){
  29. if (S(c1) == N){
  30. break;
  31. }
  32. if (S(c1) > N){
  33. can = 0;
  34. break;
  35. }
  36. c1++;
  37. }
  38. }
  39. if (can){
  40. ll c2 = 0;
  41. if (c1 == 0){
  42. c2 = 0;
  43. }
  44. else{
  45. while (true){
  46. if (S(c2) == c1){
  47. break;
  48. }
  49. if (S(c2) > c1){
  50. can = 0;
  51. break;
  52. }
  53. c2++;
  54. }
  55. }
  56. if (can){
  57. return c2 == 18;
  58. }
  59. else return false;
  60. }
  61. else return false;
  62. }
  63.  
  64.  
  65. int main()
  66. {
  67. int x = 0;
  68. ll ans = -666;
  69. while (true){
  70. //cout<<x<<'\n';
  71. if (x > 4e6) {
  72. cout<<x<<'\n';
  73. break;
  74. }
  75. if (f(x)) {
  76. cout<<"x = "<<x<<'\n';
  77. break;
  78. }
  79. x++;
  80. }
  81. }
  82. //Программа может вообще не дойти -- тогда return false
Add Comment
Please, Sign In to add comment