fork download
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. #define FILE(name) if (fopen(name".inp", "r")) freopen(name".inp", "r", stdin), freopen(name".out", "w", stdout)
  6. #define ll long long
  7. #define el "\n"
  8. #define ex " "
  9. const long long maxn = 1e5 + 5;
  10. const long long mod = 1e9 + 7;
  11.  
  12. vector <ll> nt = {2,3,5,7,11,13,17,23,29,31,37} ;
  13. ll n,k;
  14.  
  15.  
  16. int main() {
  17. ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  18. FILE("test");
  19. cin >> n >> k;
  20.  
  21. ll i=2;
  22. set <ll> s;
  23. unordered_map <ll,ll> mp;
  24.  
  25. while (i<=trunc(sqrt(n))) {
  26. while (n % i == 0) {
  27. s.insert(i);
  28. mp[i]++;
  29. n/=i;
  30. }
  31. i++;
  32. }
  33. if (n > 1) {s.insert(n); mp[n]++; }
  34. ll sluoc = 1 ;
  35.  
  36. for (ll x:s)
  37. sluoc *= (mp[x] + 1);
  38.  
  39. if (sluoc * 2 == k)
  40. for (ll i : nt)
  41. if (mp[i] == 0) return cout<<i,0;
  42.  
  43. else {
  44. ll sluocmoi = 1;
  45. for (ll i:nt) {
  46. sluocmoi = sluoc + sluoc / (mp[i] + 1);
  47.  
  48.  
  49. if (sluocmoi == k) return cout<<i,0;
  50. }
  51. }
  52.  
  53. cout<<-1;
  54.  
  55.  
  56.  
  57. return 0;
  58. }
  59.  
Success #stdin #stdout 0s 5312KB
stdin
Standard input is empty
stdout
-1