a53

copii1

a53
May 9th, 2019
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.03 KB | None | 0 0
  1. #include <fstream>
  2. #include <algorithm>
  3. using namespace std;
  4. long long prim[1000010];
  5. int expp[1000010], p = 0;
  6.  
  7. int main ()
  8. {
  9. ifstream cin ("copii.in");
  10. ofstream cout ("copii.out");
  11. int c, k;
  12. long long x;
  13. cin >> c >> x;
  14. if (c == 1)
  15. {
  16. cin >> k;
  17. int m = 1;
  18. for (int i = 1; i <= k; ++i)
  19. m *= 10;
  20. int nr2 = 0, nr5 = 0;
  21. for (int i = 1; i <= x; ++i)
  22. {
  23. int ci = i;
  24.  
  25. while (ci % 5 == 0)
  26. {
  27. ++nr5;
  28. ci /= 5;
  29. }
  30. }
  31. nr2 = nr5;
  32. long long prod = 1LL;
  33. for (int i = 1; i <= x; ++i)
  34. {
  35. int ci = i;
  36. while (ci % 2 == 0 && nr2 > 0)
  37. {
  38. --nr2;
  39. ci /= 2;
  40. }
  41. while (ci % 5 == 0 && nr5 > 0)
  42. {
  43. --nr5;
  44. ci /= 5;
  45. }
  46. prod *= 1LL * ci;
  47. prod %= 1LL * m;
  48. }
  49. int aux = prod, p = 0;
  50. while (aux > 0)
  51. {
  52. ++p;
  53. aux /= 10;
  54. }
  55. for (int i = p + 1; i <= k; ++i)
  56. cout << 0;
  57.  
  58. cout << prod << '\n';
  59. }
  60. else
  61. {
  62. long long i = 2LL;
  63. while (i * i <= x)
  64. {
  65. if (x % i == 0LL)
  66. {
  67. prim[++p] = i;
  68. while (x % i == 0)
  69. {
  70. x /= i;
  71. ++expp[p];
  72. }
  73. }
  74. i += 1LL;
  75. }
  76. if (x > 1LL)
  77. {
  78. prim[++p] = x;
  79. expp[p] = 1;
  80. }
  81. long long divizor = 1LL, numar = 1LL;
  82. for (int i = 1; i <= p; ++i)
  83. {
  84. if (expp[i] % 2 == 1) --expp[i];
  85.  
  86. for (int j = 1; j <= expp[i]; ++j)
  87. divizor *= prim[i];
  88. numar *= 1LL * (1 + expp[i]);
  89. }
  90. cout << divizor << " " << numar << '\n';
  91. }
  92. return 0;
  93. }
Advertisement
Add Comment
Please, Sign In to add comment