Created
August 15, 2021 15:06
-
-
Save PedroRacchetti/ce03c9be45233f350184a928da228504 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<bits/stdc++.h> | |
using namespace std; | |
long long int n; | |
int main(){ | |
scanf("%lld", &n); //Lê o intero da entrada. | |
int cnt = 0; //Váriavel contadora, que será a primeira parte da resposta. | |
long long int maxn = n; //Váriavel que mantem o maior máximo, que sabemos que é pelo menos n. | |
while(n != 1){ //enquanto não se atinge 1, | |
//Simula o algoritmo, com a operação de modularidade | |
if(n%2 == 0) n = n/2; | |
else n = 3*n + 1; | |
//Atualiza as variáveis de resposta | |
cnt++; | |
maxn = max(n, maxn); | |
} | |
//Imprime a resposta | |
printf("%d %lld\n",cnt, maxn ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment