mirror of
https://gitlab.gwdg.de/j.hahn02/university.git
synced 2026-01-01 06:44:25 -05:00
10 lines
181 B
C
10 lines
181 B
C
int sequence(int x, int n){
|
|
if (n < 0) return 0;
|
|
for (int i = 0; i < n; i++) {
|
|
if (x % 2 == 0) x = x/2;
|
|
else x = 3 * x + 1;
|
|
if (x < 0) return -1;
|
|
}
|
|
return x;
|
|
};
|