Advertisement
Guest User

acmp.ru 257

a guest
Dec 30th, 2020
314
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.38 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. typedef long long ll;
  5. vector <ll> s;
  6.  
  7. ll check(ll n, ll a, ll b, ll c, ll d){
  8.     return (a*n*n*n+b*n*n+c*n+d);
  9. }
  10.  
  11. void poisk(ll n, ll a, ll b, ll c, ll d){
  12.     for (ll i = 1; i*i <= abs(n); i++){
  13.         if (n % i == 0){                   
  14.             if (check(i, a, b, c, d) == 0)
  15.                 s.push_back(i);
  16.             if (check(n/i, a, b, c, d) == 0)
  17.                 s.push_back(n/i);
  18.             if (check(-1*i, a, b, c, d) == 0)
  19.                 s.push_back(-1*i);
  20.             if (check(-1*n/i, a, b, c, d) == 0)
  21.                 s.push_back(-1*n/i);
  22.         }
  23.     }
  24. }
  25.  
  26. int main(){
  27.     ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  28.     ll a, b, c, d;
  29.     cin >> a >> b >> c >> d;   
  30.     if (a == 0 and b == 0 and c == 0 and d == 0){
  31.         cout << -1;
  32.         return 0;
  33.     }
  34.     if (a != 0 and b!=0 and c==0 and d==0 or a == 0 and b == 0 and c != 0 and d == 0 or a == 0 and b != 0 and c == 0 and d == 0 or a != 0 and b == 0 and c == 0 and d == 0 or a != 0 and b == 0 and c != 0 and d == 0 or a!= 0 and b!=0 and c!=0 and d==0)
  35.         s.push_back(0);
  36.     if (a == 0 and b != 0 and c != 0 and d == 0 or a != 0 and b == 0 and c != 0 and d == 0 or a!= 0 and b!=0 and c!=0 and d==0)
  37.         poisk(c, a, b, c, d);
  38.     if (a != 0 and b!=0 and c==0 and d==0) 
  39.         poisk(b, a, b, c, d);  
  40.     poisk(d, a, b, c, d);  
  41.     sort(s.begin(), s.end());
  42.     s.erase((unique(s.begin(), s.end())), s.end());
  43.     cout << s.size();
  44.     for (ll i = 0; i < s.size(); i++)
  45.         cout << " " << s[i];
  46.     return 0;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement