using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace Breaking_Sticks { class Program { static long Help1(long[] ar, long st, List simp) { long res = -1; for (long i =st; i < ar.Length; i++) { if(ar[i]==0) { res=i; simp.Add(res); break; } } return res; } static void Methed (long[] ar, List simp,long st) { while (st < ar.Length) { long start = Help1(ar, st, simp); if (start != -1) { Help(ar, simp, start); st = start; } else { return; } } } static void Help(long[] ar, List simp, long start) { long temp = simp[simp.Count - 1]; for (long i = temp; i < ar.Length;) { ar[i] = temp; i = i + temp; } } static void ForSimplNumbers(long number, List num, List stepen , List simpl) { bool f = true; int i = 0; while(f==true) { if (number == 1) { f = false; } else { if (number % simpl[i] == 0) { num.Add(simpl[i]); number = number / simpl[i]; stepen.Add(1); while (number % simpl[i] == 0) { number = number /simpl[i]; stepen[stepen.Count-1]++; } } else { i++; if(i == simpl.Count && number != 1) { num.Add(number); stepen.Add(1); return; } } } } } static long Cnt(int count, List num, List stepen) { if (count == 0) return 1; if(stepen[count - 1] == 1) { stepen[count - 1] = stepen[count - 1] - 1; return 1 + num[count - 1] * Cnt(--count, num, stepen); } else { stepen[count - 1] = stepen[count - 1] - 1; return 1 + num[count - 1] * Cnt(count, num, stepen); } } static long CountStep2(long a, List simpl) { List num = new List(); List stepen = new List(); ForSimplNumbers(a, num, stepen, simpl); return Cnt(num.Count, num, stepen); } static long CountStep(long a, List simpl) { long res = 1; List num = new List(); List stepen = new List(); ForSimplNumbers(a, num, stepen, simpl); int count = num.Count; long temp = num[count - 1]; if ((stepen[count - 1] - 1) == 0) { //stepen.RemoveAt(stepen.Count - 1); //num.RemoveAt(num.Count - 1); count--; } else { stepen[count - 1]--; } res = res + temp; while (count>0) { long temp2 = num[count - 1]; if((stepen[count - 1]-1)==0) { //stepen.RemoveAt(stepen.Count - 1); //num.RemoveAt(num.Count - 1); count--; } else { stepen[count - 1]--; } res = res + temp2* temp; temp = temp2* temp; } return res; } static long longestSequence(long[] a) { long res = 0; long[] allnum = new long[1000001]; List simpl = new List(); Methed(allnum, simpl, 2); for( long i=0;i