AtCoderのABC
次のABCの問題へ
前のABCの問題へ
ABC193-C Unexpressed
C#のソース
using System;
using System.Collections.Generic;
using System.Linq;
class Program
{
static string InputPattern = "InputX";
static List<string> GetInputList()
{
var WillReturn = new List<string>();
if (InputPattern == "Input1") {
WillReturn.Add("8");
//6
}
else if (InputPattern == "Input2") {
WillReturn.Add("100000");
//99634
}
else {
string wkStr;
while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
}
return WillReturn;
}
static void Main()
{
List<string> InputList = GetInputList();
long N = long.Parse(InputList[0]);
var ProdSet = new HashSet<long>();
for (long A = 2; A * A <= N; A++) {
long ProdVal = A;
for (long B = 2; B < long.MaxValue; B++) {
ProdVal *= A;
if (ProdVal <= N) {
ProdSet.Add(ProdVal);
}
if (ProdVal > N) break;
}
}
Console.WriteLine(N - ProdSet.Count);
}
}
解説
2以上のAとBを全探索してます。