Advertisement
Solingen

z3.1.cpp

Dec 21st, 2024
21
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.83 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. // Приведение к [0..6]
  5. int mod7(int x)
  6. {
  7.     return (x % 7 + 7) % 7;
  8. }
  9.  
  10. int main()
  11. {
  12.     // Пусть у нас многочлен P(x) = a*x^2 + b*x + c (для примера)
  13.     // Или расширяйте на степень 3,4 по аналогии
  14.     int a, b, c;
  15.     cout << "Введите a, b, c (F7): ";
  16.     cin >> a >> b >> c;
  17.  
  18.     a = mod7(a);
  19.     b = mod7(b);
  20.     c = mod7(c);
  21.  
  22.     bool foundAny = false;
  23.     cout << "Корни (x), где P(x)=0 (mod 7): ";
  24.     for (int x = 0; x < 7; x++)
  25.     {
  26.         int val = mod7(a*x*x + b*x + c);
  27.         if (val == 0)
  28.         {
  29.             cout << x << " ";
  30.             foundAny = true;
  31.         }
  32.     }
  33.     if (!foundAny) cout << "Нет корней в F7";
  34.     cout << endl;
  35.     return 0;
  36. }
  37.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement