void Calc() { Generateprimenumber P = new Generateprimenumber(100000); long count = 0; long[] div = P.Divisor(N); Array.Sort(div); Map m = new Map(div); for (int i = 0; i < div.Length; i++) { long[] div2 = P.Divisor(div[i]); long c = Pow(K, (div[i] + 1) / 2); for (int j = 0; j < div2.Length; j++) { c = (c + Define.mod - m.Get(div2[j])) % Define.mod; } m.Set(div[i], c); if (div[i] % 2 == 0) { c = c * (div[i] / 2) % Define.mod; } else { c = c * div[i] % Define.mod; } count = (count + c) % Define.mod; } sb.Append(count + "\n"); }
void Calc() { getinput(); Generateprimenumber p1 = new Generateprimenumber(2154); Generateprimenumber p2 = new Generateprimenumber(100000); Map m1; Map m2; List <long> e = new List <long>(); List <long> q = new List <long>(); { long[] pp = new long[p2.length]; for (int i = 0; i < p2.length; i++) { pp[i] = (long)(p2.p[i]) * (long)(p2.p[i]); } m1 = new Map(pp, p2.p); } { long[] f = new long[N]; for (int i = 0; i < N; i++) { long a = s[i]; for (int j = 0; j < p1.length; j++) { long k = (long)p1.p[j] * (long)p1.p[j] * (long)p1.p[j]; while (true) { if (a % k == 0) { a /= k; } else { break; } } } f[i] = a; } Array.Sort(f); int count = 1; List <int> d = new List <int>(); e.Add(f[0]); for (int i = 1; i < N; i++) { if (f[i - 1] == f[i]) { count++; } else { d.Add(count); count = 1; e.Add(f[i]); } } d.Add(count); m2 = new Map(e.ToArray(), d.ToArray()); } for (int i = 0; i < e.Count; i++) { long a = e[i]; long b = 1; long c; bool y = false; try{ checked { for (int j = 0; j < p1.length; j++) { if (a % ((long)p1.p[j] * (long)p1.p[j]) == 0) { a /= ((long)p1.p[j] * (long)p1.p[j]); b *= p1.p[j]; } else if (a % p1.p[j] == 0) { a /= p1.p[j]; b *= ((long)p1.p[j] * (long)p1.p[j]); } } c = m1.Get(a); if (c == -1) { c = a * a; } b *= c; } } catch (OverflowException ex) { y = true; } if (y) { q.Add(-1); } else { q.Add(b); } } { int count = 0; if (e[0] == 1) { count++; for (int i = 1; i < e.Count; i++) { int y = m2.Get(q[i]); if (y == -1) { count += m2.data[i]; } else if (e[i] < q[i]) { count += m2.data[i] <= y ? y : m2.data[i]; } } } else { for (int i = 0; i < e.Count; i++) { int y = m2.Get(q[i]); if (y == -1) { count += m2.data[i]; } else if (e[i] < q[i]) { count += m2.data[i] <= y ? y : m2.data[i]; } } } Console.WriteLine(count); } }
void Calc() { int N = int.Parse(Console.ReadLine()); string[] str = Console.ReadLine().Split(' '); int[] X = new int[N]; for (int i = 0; i < N; i++) { X[i] = int.Parse(str[i]); } List <int> Diff = new List <int>(); Diff.Add(X[0]); Diff.Add(X[N - 1] + 1); for (int i = 1; i < N; i++) { if (X[i] != X[i - 1] + 1) { Diff.Add(X[i]); } } for (int i = 0; i < N - 1; i++) { if (X[i] + 1 != X[i + 1]) { Diff.Add(X[i] + 1); } } int[] diff = Diff.ToArray(); int o = 0; int e = 0; for (int i = 0; i < diff.Length; i++) { if (diff[i] % 2 == 0) { e++; } else { o++; } } int[] Odd = new int[o]; int[] Even = new int[e]; o = 0; e = 0; for (int i = 0; i < diff.Length; i++) { if (diff[i] % 2 == 0) { Even[e] = diff[i]; e++; } else { Odd[o] = diff[i]; o++; } } List <int> f = new List <int>(); List <int> t = new List <int>(); List <long> capa = new List <long>(); int S = 0; int Ef = 1; int Of = e + 1; int T = o + e + 1; for (int i = 0; i < e; i++) { f.Add(S); t.Add(Ef + i); capa.Add(1); } for (int i = 0; i < o; i++) { f.Add(Of + i); t.Add(T); capa.Add(1); } Generateprimenumber G = new Generateprimenumber(10000); for (int i = 0; i < e; i++) { for (int j = 0; j < o; j++) { if (G.Prime(Math.Max(Even[i] - Odd[j], Odd[j] - Even[i]))) { f.Add(Ef + i); t.Add(Of + j); capa.Add(1); } } } MaxFlow Flow = new MaxFlow(f.ToArray(), t.ToArray(), capa.ToArray(), o + e + 2, 0, o + e + 1); int flow = (int)Flow.flow; int count = diff.Length - flow; if (e % 2 != flow % 2) { count++; } sb.Append(count + "\n"); }