Skip to content

Instantly share code, notes, and snippets.

@RimuruDev
Last active November 28, 2022 09:49
Show Gist options
  • Save RimuruDev/d75fc5f373b7d29f8cea66ebda9139c9 to your computer and use it in GitHub Desktop.
Save RimuruDev/d75fc5f373b7d29f8cea66ebda9139c9 to your computer and use it in GitHub Desktop.
Дано действительное число х. Не пользуясь никакими други- ми арифметическими операциями, кроме умножения, сложения и вычитания, вычислить за минимальное число операций 2Х4- Зх3+ 4х2- 5х + 6. #RimuruDev
// Если это решение вам помогло, ставьте + в комментариях.
// If this solution helped you, put + in the comments.
using System;
namespace Honey
{
internal sealed class Kaipal
{
private static void Main()
{
Console.WriteLine(ComputingWithLocalPow(4)); // result: 370
Console.ReadKey();
}
private static int ComputingWithLocalPow(int x) => 2 * Pow(x, 4) - 3 * Pow(x, 3) + 4 * Pow(x, 2) - 5 * x + 6;
private static int Pow(int num, int pow)
{
int result = 1;
for (int i = 0; i < pow; i++)
{
result *= num;
}
return result;
}
}
}
// Made Rimuru Dev for Kaipal 28.11.2022 11:08 Samara
// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// ///
// Task: => ///
// Дано действительное число х. Не пользуясь никакими другими ///
// арифметическими операциями, кроме умножения, сложения ///
// и вычитания, вычислить за минимальное число операций 2Х4- Зх3+ 4х2- 5х + 6. ///
// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// /// ///
namespace Honey
{
using System;
internal sealed class Kaipal
{
private static void Main()
{
Console.WriteLine(Pow(6, 6)); // result: 46656
Console.WriteLine(ComputingWithLocalPow(4)); // result: 370
Console.WriteLine(ComputingWithMathPow(4)); // result: 370
Console.ReadKey();
}
// Решение задачи с помощью Math.Pow, что противоречит условию задачи.
private static int ComputingWithMathPow(int x) => (int)(2 * Math.Pow(x, 4) - 3 * Math.Pow(x, 3) + 4 * Math.Pow(x, 2) - 5 * x + 6);
// Решение задачи с помощью своего метода Pow, что удовлетворяет условию задачи.
private static int ComputingWithLocalPow(int x) => 2 * Pow(x, 4) - 3 * Pow(x, 3) + 4 * Pow(x, 2) - 5 * x + 6;
/// <param name="num"> Число Х из формулы.</param>
/// <param name="pow">Возвение в степень.</param>
private static int Pow(int num, int pow)
{
int result = 1;
for (int i = 0; i < pow; i++)
{
result *= num;
}
return result;
}
}
}
@RimuruDev
Copy link
Author

изображение

@RimuruDev
Copy link
Author

Если это решение вам помогло, ставьте + в комментариях.
If this solution helped you, put + in the comments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment