fork(1) download
  1. #define _CRT_SECURE_NO_WARNINGS
  2.  
  3. #include<bits/stdc++.h>
  4.  
  5. using namespace std;
  6.  
  7. #define PI 3.14159265
  8. #define OO 1e9
  9. #define SS second
  10. #define FF first
  11. #define Trace(n) cout<< #n <<" = "<< n << endl;
  12. #define ll long long
  13. #define endl "\n"
  14.  
  15. int dx[] = { 0, 0, -1, 1, 1, 1, -1, -1 };
  16. int dy[] = { -1, 1, 0, 0, 1, -1, 1, -1 };
  17.  
  18. void TimeElapsed()
  19. {
  20. #ifndef ONLINE_JUDGE
  21. cout << endl;
  22. cout << "Time Elapsed :" << 1.0*clock() / CLOCKS_PER_SEC << " s." <<
  23.  
  24. endl;
  25. #endif
  26. }
  27.  
  28. void fast()
  29. {
  30. std::ios_base::sync_with_stdio(0);
  31. cin.tie(NULL);
  32. cout.tie(NULL);
  33.  
  34. #ifndef ONLINE_JUDGE
  35. freopen("input.txt", "r", stdin);
  36. freopen("output.txt", "w", stdout);
  37. #endif
  38.  
  39. }
  40.  
  41. void setWinner(string &w)
  42. {
  43. if (w == "Stan wins")
  44. w = "Ollie wins";
  45. else
  46. w = "Stan wins";
  47. }
  48.  
  49. int main()
  50. {
  51. fast();
  52. int n, m;
  53. while (cin >> n >> m)
  54. {
  55. if (n == 0 && m == 0)
  56. break;
  57.  
  58. if (n < m)
  59. swap(n, m);
  60.  
  61. string ans = "Stan wins"; // or "Ollie wins"
  62.  
  63. while (true)
  64. {
  65. if (n % m == 0 || n / m > 1)
  66. {
  67. cout << ans << endl;
  68. break;
  69. }
  70.  
  71. n %= m;
  72. swap(n, m);
  73. setWinner(ans);
  74. }
  75. }
  76. }
Success #stdin #stdout 0s 15240KB
stdin
1111111111 2
1 1
36 20
28 20
25 7
4 4
8 4
12 8
20 8
34 12
15 24
0 0
stdout
Stan wins
Stan wins
Stan wins
Ollie wins
Stan wins
Stan wins
Stan wins
Ollie wins
Stan wins
Stan wins
Ollie wins