Код на C++:
#include <iostream>
using namespace std;
int main()
{
setlocale(LC_ALL, "rus");
int f1 = 0;
int f2 = 1;
int f3 = 1;
int A, count = 0;
do
{
cin >> A;
} while (A < 2 || A > 2 * pow(10, 9));
while (true)
{
count++;
if (f3 == A)
{
cout << count << endl;
break;
}
else if (f3 != A && f3 > A)
{
cout << -1 << endl;
break;
}
f3 = f1 + f2;
f1 = f2;
f2 = f3;
};
return 0;
}
Объяснение:
// Поскольку о работе с комплексными числами не говорилось, написал метод для решения квадратного уравнения в вещественных числах (d >= 0).
// Solve -- метод, обеспечивающий решение.
using System;
namespace ConsoleApp1
{
internal class Program
{
private static void Main(string[] args)
{
double a, b, c;
Console.Write("a = ");
a = double.Parse(Console.ReadLine());
Console.Write("b = ");
b = double.Parse(Console.ReadLine());
Console.Write("c = ");
c = double.Parse(Console.ReadLine());
if (a == 0)
{
Console.WriteLine("incorrect data");
return;
}
Console.WriteLine();
Solve(a, b, c);
Console.ReadLine();
}
private static void Solve(double a, double b, double c)
{
double d = b * b - 4 * a * c;
if (d < 0)
{
Console.WriteLine("No solutions");
return;
}
double sd = Math.Sqrt(d);
double x1 = (-b + sd) / (2 * a);
double x2 = (-b - sd) / (2 * a);
if (d == 0)
{
Console.WriteLine($"x = {x1}");
return;
}
Console.WriteLine($"x1 = {x1}");
Console.WriteLine($"x2 = {x2}");
}
}
}