沐咕 @ 2024-11-08 21:34:30
#include <bits/stdc++.h>
using namespace std;
long long a, b;
set<long long> s;
int main()
{
cin >> a >> b;
s.insert(a);
s.insert(b);
long long x = a, y = b;
while (true)
{
if (s.find(abs(y - x)) != s.end())
break;
s.insert(abs(y - x));
x = y;
y = abs(y - x);
}
cout << s.size() << endl;
return 0;
}
by MLE_Automaton @ 2024-11-08 21:38:58
@沐咕 这个应该是出现0才循环吧
by 沐咕 @ 2024-11-08 21:39:36
by DDD_et @ 2024-11-08 21:39:45
@MLE_Automaton
有道理,出现 0 或者像我刚才说的那样都会循环
by ran_qwq @ 2024-11-08 21:40:18
@ran_qwq *x已经被赋值成y了
by DDD_et @ 2024-11-08 21:40:37
@沐咕
当 x = y
后 abs (y - x)
难道不等于
by 沐咕 @ 2024-11-08 21:40:52
@ran_qwq
这样也不对,还是 10 分(
#include <bits/stdc++.h>
using namespace std;
long long a, b;
set<long long> s;
int main()
{
cin >> a >> b;
s.insert(a);
s.insert(b);
long long x = a, y = b;
while (true)
{
if (s.find(abs(y - x)) != s.end())
break;
s.insert(abs(y - x));
long long xx = x, yy = y;
x = yy;
y = abs(yy - xx);
}
cout << s.size() << endl;
return 0;
}
by __Louis__ @ 2024-11-08 21:41:10
这题不应该是什么 gcd 之类的题吗,用set大概率会T
by DDD_et @ 2024-11-08 21:41:25
改成这样?
while (true)
{
if (s.find(abs(y - x)) != s.end())
break;
s.insert(abs(y - x));
long long tx = x;
x = y;
y = abs(y - tx);
}
by 沐咕 @ 2024-11-08 21:41:31
@DDD_et @ran_qwq 所以能给个代码吗,不知道咋改,知道问题出在哪qwq
by DDD_et @ 2024-11-08 21:41:46
用来替换原来的 while
循环