典型90問
次の典型90問へ
前の典型90問へ
典型90問 020 Log Inequality(★3)
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("4 3 2");
//Yes
}
else if (InputPattern == "Input2") {
WillReturn.Add("16 3 2");
//No
}
else if (InputPattern == "Input3") {
WillReturn.Add("8 3 2");
//No
}
else {
string wkStr;
while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
}
return WillReturn;
}
static void Main()
{
List<string> InputList = GetInputList();
long[] wkArr = InputList[0].Split(' ').Select(pX => long.Parse(pX)).ToArray();
long A = wkArr[0];
long B = wkArr[1];
long C = wkArr[2];
long CurrVal = C;
for (long I = 2; I <= B; I++) {
if (WillOverProd(CurrVal, C, A)) {
Console.WriteLine("Yes");
return;
}
CurrVal *= C;
}
Console.WriteLine("No");
}
// 2正数の掛け算が、Limitを超えるかを返す
static bool WillOverProd(long pA, long pB, long pLimit)
{
return pA > pLimit / pB;
}
}
解説
a < (cのb乗)
の判定問題に変形して、解いてます。