using System; using System.Collections.Generic; using System.IO; using System.Linq; class Solution { static long longestSequence(long[] a) { // Return the length of the longest possible sequence of moves. long result = 0; for (int i = 0; i < a.Length; i ++) { result = result + getLongestSequenceForOneStick(a[i]); } return result; } private static long getLongestSequenceForOneStick(long n) { if (n == 1) return 1; long previousNumber = 1; long remainder = 0; long move = 0; move = getLongestMove(n, previousNumber, ref remainder); long finalMove = move; while (remainder > 1) //continue to find move { long newN = remainder; move = getLongestMove(newN, move, ref remainder); finalMove = finalMove + move; } return finalMove + 1; //for the orignal stick } static long getLongestMove(long n, long previousNumber, ref long remainder) { int maxK = 36; //2^36 < 10^12 int k = maxK; long whole = 0; while (k >= 0) { long pow = (long)Math.Pow(2,k); if (n % pow == 0) { whole = n / pow; if (whole == 1) // a whole need to bigger than 2 to ensure that alg run correctly. { k--; continue; } else break; //already find out k } k--; //continue find k } //already have k, and the whole. //need to return the remainder number need to find the longest move. It is 2^k remainder = (long)Math.Pow(2, k); return whole * previousNumber; } static void Main(String[] args) { int n = Convert.ToInt32(Console.ReadLine()); string[] a_temp = Console.ReadLine().Split(' '); long[] a = Array.ConvertAll(a_temp,Int64.Parse); long result = longestSequence(a); Console.WriteLine(result); } }