Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define all(a) (a).begin(), (a).end()
- #define ret return
- #include <iostream>
- #include <stdio.h>
- #include <cstdio>
- #include <vector>
- #include <map>
- #include <set>
- #include <string>
- #include <algorithm>
- #include <cmath>
- using namespace std;
- int main()
- {
- long long n; cin >> n;
- int d; cin >> d;
- if (n == 0 && d == 0){
- cout << 2 << ' ' << 1;
- ret 0;
- }
- if (n < d){
- cout << 2 << ' ' << 0;
- ret 0;
- }
- if (n == d)
- {
- cout << n + 1 << ' ' << 1;
- ret 0;
- }
- long long x = n - d;
- int ans = 0; long long pos = 2;
- vector< long long> D;
- for (long long i = 2; i*i < x; ++i)
- {
- if (x % i == 0)
- {
- D.push_back(i);
- if (i*i != x)
- D.push_back(x / i);
- }
- }
- D.push_back(x);
- sort(all(D));
- for (int i = 0; i < D.size(); ++i)
- {
- if (D[i] == 1)continue;
- long long k = D[i];
- long long cur = n;
- int cnt = 0;
- while (cur && cur % k == d)
- {
- cnt++;
- cur/= k;
- }
- if (ans < cnt)
- {
- ans = cnt;
- pos = k;
- }
- }
- cout << pos << ' ' << ans;
- //system("pause");
- ret 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement