Archives
Trending
Support
Login
clear text
XML
Django
JavaScript
MATLAB
C
C++
C#
Python
SQL
Shell
Bash
Markdown
YAML
JSON
HTML
CSS
PHP
Java
Ruby
Go
Rust
Swift
Kotlin
Arduino
TypeScript
Perl
Autohotkey
Lua
SQF
R
Scala
Haskell
Groovy
Dart
Clojure
VB.NET
Objective-C
PowerShell
Bash
CoffeeScript
Verilog
#include
//#include
#include
#include
using namespace std; typedef long long ll; map
A; void simulate(ll x) { int cnt = 0; A[x] = cnt; while(x != 1) { cnt++; if(x % 2 == 0) { x /= 2; } else { x *= 3; x++; } if(!A.count(x)) { A[x] = cnt; } } } int main() { ll a, b; while(cin >> a >> b) { A.clear(); if(a == 0 and b == 0) { break; } simulate(a); ll tmp = b; int cnt = 0; while(true) { if(A.count(b)) { break; } if(b % 2 == 0) { b /= 2; } else { b *= 3; b++; } cnt++; } cout << a << " needs " << A[b] << " steps, " << tmp << " needs " << cnt << " steps, they meet at " << b << endl; } return 0; } /* 7 needs 13 steps, 8 needs 0 steps, they meet at 8 27 needs 95 steps, 30 needs 2 steps, they meet at 46 **/
Mark as private (unlisted)
for 30 minutes
for 6 hours
for 1 day
for 1 week
for 1 month
for 1 year
everlasting (like CCCP)