using System; using System.Collections.Generic; using System.Linq; class Program { static string InputPattern = "InputX"; static List GetInputList() { var WillReturn = new List(); if (InputPattern == "Input1") { WillReturn.Add("81"); //315 } else if (InputPattern == "Input2") { WillReturn.Add("216"); //858 } else if (InputPattern == "Input3") { WillReturn.Add("10000000000"); //30756925116342 } else { string wkStr; while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr); } return WillReturn; } static long[] GetSplitArr(string pStr) { return (pStr == "" ? new string[0] : pStr.Split(' ')).Select(pX => long.Parse(pX)).ToArray(); } static void Main() { List InputList = GetInputList(); long N = long.Parse( InputList[0]); long Jyougen = 1; for (long I = 1; I * I <= N; I++) { Jyougen = I; } Eratosthenes(Jyougen); long Answer = 0; foreach (long EachSosuu in mSosuuArr) { long CurrVal = EachSosuu * EachSosuu; while (true) { if (CurrVal <= N) { Answer += CurrVal; } else { break; } CurrVal *= EachSosuu; } } Console.WriteLine(Answer); } static long[] mSosuuArr; // エラトステネスの篩 static void Eratosthenes(long pJyougen) { bool[] IsSosuuArr = new bool[pJyougen + 1]; for (int I = 2; I <= IsSosuuArr.GetUpperBound(0); I++) { IsSosuuArr[I] = true; } for (int I = 2; I * I <= IsSosuuArr.GetUpperBound(0); I++) { if (IsSosuuArr[I]) { for (int J = I * 2; J <= IsSosuuArr.GetUpperBound(0); J += I) { IsSosuuArr[J] = false; } } } var SosuuList = new List(); for (int I = 2; I <= IsSosuuArr.GetUpperBound(0); I++) { if (IsSosuuArr[I]) SosuuList.Add(I); } mSosuuArr = SosuuList.ToArray(); } }