Advertisement
Guest User

Untitled

a guest
Oct 21st, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. #define _CRT_SECURE_NO_WARNINGS
  2. #include <iostream>
  3. #include <string>
  4. #include <vector>
  5. #include <iomanip>
  6. #include <math.h>
  7. #include <cmath>
  8. #include <algorithm>
  9. #include <set>
  10. #include <deque>
  11. using namespace std;
  12. vector<vector<int>> kek(3);
  13. vector<int> ans;
  14.  
  15. int nod(int a, int b) {
  16. while (b != 0) {
  17. int buf = b;
  18. b = a % b;
  19. a = buf;
  20. }
  21. return a;
  22. }
  23.  
  24. int main() {
  25. int n;
  26. cin >> n;
  27. for (int i = 0; i < n; i++) {
  28. int num;
  29. cin >> num;
  30. if (num == 1) {
  31. cout << "Impossible";
  32. return 0;
  33. }
  34. for (int j = 0; j < 3; j++) {
  35. if (kek[j].size() == 0) {
  36. kek[j].push_back(num);
  37. ans.push_back(j + 1);
  38. break;
  39. }
  40. auto k = nod(kek[j][0], num);
  41. if (k != 1) {
  42. kek[j][0] = k;
  43. ans.push_back(j + 1);
  44. break;
  45. }
  46. }
  47. if (ans.size() != i + 1) {
  48. cout << "Impossible";
  49. return 0;
  50. }
  51. }
  52. cout << "Possible\n";
  53. for (auto i : ans) {
  54. cout << i << " ";
  55. }
  56.  
  57. //system("pause");
  58. return 0;
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement