fork download
  1. #include <iostream>
  2. #include <iomanip>
  3. #include <cmath>
  4. #include <climits>
  5. #include <algorithm>
  6. #include <numeric>
  7.  
  8. using namespace std;
  9.  
  10. const int MOD = (int)(1e9 + 7);
  11.  
  12. void find(long long n) {
  13.  
  14. int maxValue = 0, maxExponent = 0;
  15. for (long long i = 2;i * i <= n;i++) {
  16.  
  17. // Xác định i là một ước nguyên tố của n
  18. if (n % i == 0) {
  19.  
  20. // Tìm số mũ của i trong n
  21. int count = 0;
  22. while (n % i == 0) {
  23. count++;
  24. n = n / i;
  25. }
  26. if (count > maxExponent) {
  27. maxExponent = count;
  28. maxValue = i;
  29. }
  30. }
  31. }
  32.  
  33. // Ước nguyên tố cuối cùng trong phân tích
  34. if (n != 1) {
  35. if (maxExponent < 1) {
  36. maxExponent = 1;
  37. maxValue = n;
  38. }
  39. }
  40. cout << maxValue << " " << maxExponent << endl;
  41. }
  42.  
  43. int main() {
  44. ios_base::sync_with_stdio(false);
  45. cin.tie(NULL);
  46.  
  47. long long n;cin >> n;
  48. find(n);
  49. return 0;
  50. }
  51.  
  52.  
Success #stdin #stdout 0.01s 5320KB
stdin
Standard input is empty
stdout
2 13