// aarifshuvo ``CSEJU #include <bits/stdc++.h> #define ll long long #define SZ(x) ((int)(x).size()) #define scl(x) scanf("%lld", &x) #define scll(x,y) scanf("%lld %lld", &x, &y) #define ALL(x) (x).begin(),(x).end() #define REP(i,n) for(int i=0;i<n;i++) #define REV(i,n) for(int i=n-1;i>=0;i--) #define FOR(i,a,b) for(int i=a;i<=b;i++) #define pri(a) cout<<a<<endl #define prii(a,b) cout<<a<<" "<<b<<endl using namespace std; ll cnt, ans; void cal(ll n, ll cnt) { if(n==0) { ans=min(ans,cnt); return; } if(n%2==0) cal(n/2,cnt+1); else { cal(n-1, cnt+1); if(n!=1) cal(n+1,cnt+1); } } int main() { ll a; while(scl(a)==1) { cnt = 0; ans = 99999999 cal(a, cnt); printf("%lld\n", ans); } }
~Be glad of life because it gives you the chance to love and to work and to play and to look at the stars.~
Thursday, June 1, 2017
UVa 11567 Moliu Number Generator
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment