Advertisement
Guest User

Untitled

a guest
Oct 20th, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.36 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define endl '\n'
  3. #define int long long
  4. using namespace std;
  5. signed main() {
  6. string s;
  7. cin>>s;
  8. int last = s[s.size() - 1] - '0';
  9. if(last == 0)
  10. {
  11. cout<<2<<" "<<2<<endl;
  12. return 0;
  13. }
  14. if(s == "1" || s == "2" || s == "3" || s == "5" || s == "7")
  15. {
  16. cout<<-1<<endl;
  17. return 0;
  18. }
  19. if(s == "4" || s == "8")
  20. {
  21. cout<<10<<" "<<2<<endl;
  22. return 0;
  23. }
  24. if(s == "9" || s == "6")
  25. {
  26. cout<<10<<" "<<3<<endl;
  27. return 0;
  28. }
  29. if(last != 1)
  30. {
  31. cout<<last * 5<<" "<<last<<endl;
  32. return 0;
  33. }
  34. int sum = 0;
  35. for(auto i : s)
  36. {
  37. sum += i - 48;
  38. }
  39. sum--;
  40. vector<int> arr = {2,3, 5, 7, 11, 13, 17, 19, 21, 23, 29};
  41. int p = -1;
  42. for(auto i : arr)
  43. {
  44. if(sum % i)
  45. {
  46. p = i;
  47. break;
  48. }
  49. }
  50. int start = 10;
  51. int end = start + p ;
  52. for(; start <= end; start++)
  53. {
  54. int pr = 1, u = 0;
  55. for(int i = s.size() - 1; i > -1; i--)
  56. {
  57. u += (s[i] - '0') * pr;
  58. u %= p;
  59. pr *= start;
  60. pr %= p;
  61. }
  62. if(u % p == 0)
  63. {
  64. cout<<start<<" "<<p<<endl;
  65. return 0;
  66. }
  67. }
  68. cout<<-1<<endl;
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement