Advertisement
Guest User

Untitled

a guest
Dec 12th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. #include <algorithm>
  4. #include <vector>
  5. #include <string>
  6. #include <math.h>
  7. #define ll long long
  8. using namespace std;
  9. //freopen("a.in", "r", stdin);
  10. //freopen("a.out", "w", stdout);
  11.  
  12. int n;
  13.  
  14. ll v_n_sum(ll t){
  15. ll sum = 0;
  16. while(t > 0){
  17. sum += t % n;
  18. t /= n;
  19. }
  20. return sum;
  21. }
  22.  
  23.  
  24. int main()
  25. {
  26. ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  27. ll x = 1, y;
  28. cin >> n;
  29. bool f = false;
  30. ll now = 1;
  31. ll sum_n, sum_del;
  32. bool count = false;
  33. bool g;
  34. while(true){
  35. g = false;
  36. sum_del = 0;
  37. sum_n = v_n_sum(x);
  38. y = x;
  39. for (ll i = 2; i*i <= y; i++) {
  40. while (y % i == 0) {
  41. g = true;
  42. sum_del += v_n_sum(i);
  43. y /= i;
  44. }
  45. }
  46. if(g){
  47. if (y > 1)
  48. sum_del += v_n_sum(y);
  49. if(sum_n == sum_del){
  50. if(f){
  51. if(!count){
  52. count = true;
  53. f = false;
  54. } else{
  55. cout << now;
  56. return 0;
  57. }
  58. }else{
  59. now = x;
  60. f = true;
  61. }
  62. } else
  63. f = false;
  64. } else
  65. f = false;
  66. x++;
  67. }
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement