fork(11) download
  1. #include <iostream>
  2. #include <vector>
  3. #include <string>
  4. using namespace std;
  5.  
  6.  
  7. const int BASE = 1000000000;
  8. #ifndef DBG
  9. const int MAX = 100000;
  10. #else
  11. const int MAX = 500;
  12. #endif
  13.  
  14. const string WHITESPACE = " \n\r\t\f\v";
  15. void trim(string& s) {
  16. s.erase(s.find_last_not_of(WHITESPACE) + 1);
  17. s.erase(0,s.find_first_not_of(WHITESPACE));
  18. }
  19.  
  20. struct big_num {
  21. vector<int> a;
  22. size_t size() const {
  23. return a.size();
  24. }
  25. int& operator[](size_t index) {
  26. return a[index];
  27. }
  28. int operator[](size_t index) const {
  29. return a[index];
  30. }
  31. big_num(){}
  32. bool operator==(const big_num& b) const {
  33. if (a.size() == 0 || (a.size() == 1 && a[0] == 0)){
  34. return b.size() == 0 || (b.size() == 1 && b[0] == 0);
  35. }
  36.  
  37. if (a.size() == b.size()) {
  38. for (size_t i = 0; i < a.size(); ++i) {
  39. if (a[i] != b[i]) {
  40. return false;
  41. }
  42. }
  43.  
  44. return true;
  45. }
  46.  
  47. return false;
  48. }
  49. bool operator>(const big_num& b) const {
  50. if (a.size() < b.size()) {
  51. return false;
  52. }
  53.  
  54. if (a.size() > b.size()) {
  55. return true;
  56. }
  57.  
  58. if (a.size() == 0) {
  59. return b.size() > 1 || (b.size() == 1 && b[0] > 0);
  60. }
  61.  
  62. for (int i = int(a.size()) - 1; i >= 0; --i) {
  63. if (a[i] > b[i]) {
  64. return true;
  65. }
  66. else if (a[i] < b[i]) {
  67. return false;
  68. }
  69. }
  70.  
  71. return a[0] > b[0];
  72. }
  73. bool operator<=(const big_num& b) const {
  74. return !(*this > b);
  75. }
  76. big_num(int n) {
  77. while (n > 0) {
  78. a.push_back(n % BASE);
  79. n /= BASE;
  80. }
  81. }
  82. void operator*=(int n) {
  83. for (size_t i = 0, carry = 0; i < a.size() || carry > 0; ++i) {
  84. if (i == a.size()) {
  85. a.push_back(0);
  86. }
  87. int64_t product = a[i] * (int64_t) n + carry;
  88. a[i] = product % BASE;
  89. carry = product / BASE;
  90. }
  91. }
  92. void operator/=(int n) {
  93. if (a.size() != 0) {
  94. int64_t remainder = 0;
  95. int last_zero = a.size();
  96. bool met_larger_than_zero = false;
  97. for (int i = int(a.size()) - 1; i >= 0; --i) {
  98. remainder = remainder * BASE + a[i];
  99. a[i] = remainder / n;
  100. remainder -= a[i] * (int64_t) n;
  101.  
  102. if (!met_larger_than_zero && a[i] > 0) {
  103. last_zero = i + 1;
  104. met_larger_than_zero = true;
  105. }
  106. }
  107. //print();
  108. a.resize(last_zero);
  109. //print();
  110. }
  111. }
  112. void read() {
  113. string s;
  114. cin >> s;
  115.  
  116. //cout<<s<<'\n';
  117. trim(s);
  118. //cout<<s<<'\n';
  119.  
  120. for (int i = s.size(); i > 0; i -= 9) {
  121. a.push_back(stoi(s.substr(max(0, i - 9), min(i, 9))));
  122. }
  123. }
  124. void print() {
  125. if (a.empty()) {
  126. printf("0\n");
  127. return;
  128. }
  129. cout << a.back();
  130. for (int i = int(a.size()) - 2; i >= 0; --i) {
  131. printf("%09i", a[i]);
  132. }
  133. cout << '\n';
  134. }
  135. big_num(const big_num& b) {
  136. a.assign(b.a.begin(), b.a.end());
  137. }
  138. };
  139.  
  140. big_num operator*(int n, const big_num& m) {
  141. big_num ret(m);
  142. ret *= n;
  143. return ret;
  144. }
  145.  
  146. int main() {
  147. ios_base::sync_with_stdio(false);
  148. cin.tie(nullptr);
  149.  
  150. big_num p;
  151.  
  152. p.read();
  153. //p.print();
  154.  
  155. big_num current_product(1);
  156. //for (int i = p.a.size() - 1; i >= 0; --i) cout << p.a[i] << ' ';
  157.  
  158. for (int x = 1, y = 1; y <= MAX; ++y) {
  159. current_product *= y;
  160.  
  161. while (current_product > p) {
  162. current_product /= x;
  163. x += 1;
  164. }
  165. if (current_product == p) {
  166. cout << x << ' ' << y;
  167. break;
  168. }
  169. }
  170.  
  171. return 0;
  172. }
  173.  
Success #stdin #stdout 0.01s 5452KB
stdin
336237000107779450149150899863053055074287462192237886406639547064000598862952490521796860533014572823802253217909006719621742372706728725882050596659868079110975411138483962679938508346084223207271792996283268944087761842281406928202932735464242785184851594398913456201359779481106052765110732849811913411176664047464310404414004075844147117854752806527707703799137449625986831614054560288169513617823061186339018288110843505197027879621937810551386486381192202704615236003835875328040763485566194123386753232451105462204780357574994936441538991794481098119557221916767010244613779179482637193549320811533841971240889642801608345443371173132254119561961267863939890858337704495876853280478521651701108085941350295579031896279162073345716099401607234573622911161651958473296500896084657795335824784903030237993040661165462387935452367825135290698190040434147320098383649238748574833493209528062381197277370039650128059455320658467098672711635850537500035531942762588635220312405979250580612424310564113612800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 
stdout
11 500