Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <algorithm>
- #include <set>
- #include <list>
- #include <queue>
- #include <map>
- #include <stack>
- #include <cstring>
- #include <iomanip>
- #include <ctime>
- using namespace std;
- int k, s, p;
- int main()
- {
- cin.tie(0);
- ios::sync_with_stdio(false);
- cin >> s >> p >> k;
- if(k == 1)
- {
- if(s == p)
- {
- cout << s;
- return 0;
- }
- }
- else if(k == 2)
- {
- for(int i = 1; i <= p; i++)
- {
- if(p % i == 0)
- {
- if(i + (p/i) == s)
- {
- cout << p/i << ' ' << i;
- return 0;
- }
- }
- }
- }
- else if(k == 3)
- {
- for(int i = 1; i <= p; i++)
- {
- if(p % i == 0)
- {
- for(int j = i; j <= p; j++)
- {
- if((p/i) % j == 0)
- {
- if(i + j + ((p/i)/j) == s)
- {
- cout << (p/i)/j << ' ' << j << ' ' << i;
- return 0;
- }
- }
- }
- }
- }
- }
- else
- {
- for(int i = 1; i <= p; i++)
- {
- if(p % i == 0)
- {
- for(int j = i; j <= p; j++)
- {
- if((p/i) % j == 0)
- {
- for(int k = j; k <= p; k++)
- {
- if(((p/i)/j) % k == 0)
- {
- if(i + j + k + (((p/i)/j)/k) == s)
- {
- cout << ((p/i)/j)/k << ' ' << k << ' ' << j << ' ' << i;
- return 0;
- }
- }
- }
- }
- }
- }
- }
- }
- cout << "NO";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement