-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path116b.cpp
More file actions
38 lines (35 loc) · 756 Bytes
/
116b.cpp
File metadata and controls
38 lines (35 loc) · 756 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i < (int)(n + 1); i++)
typedef long long ll;
int main(){
ll s;
cin >> s;
ll a = s;
set<int> history;
//初項
history.insert(a);
int m = 1;
while(true){
m++;
a = (a % 2 == 0) ? (a /2 ) : (a * 3) + 1;
if(!history.count(a)){
history.insert(a);
continue;
}
break;
}
cout << m<< endl;
return 0;
}
int calcm(int m, set<int> &history,int a){
m++;
a = (a % 2 == 0) ? (a /2 ) : (a * 3) + 1;
if(!history.count(a)){
history.insert(a);
calcm(m,history,a);
} else{
return m;
}
}