fork download
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. #define ll long long
  6. #define FOR(i , a , b) for(int i = a ; i <= b; i++)
  7. #define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  8. #define maxn 100005
  9.  
  10. struct Poly{
  11. double a;
  12. ll n;
  13. };
  14.  
  15. Poly f[maxn];
  16.  
  17. double binpow(double a , ll b){
  18. double res = 1;
  19. while(b){
  20. if(b & 1){
  21. res *= a;
  22. }
  23. a *= a;
  24. b >>= 1;
  25. }
  26. return res;
  27. }
  28.  
  29. double derivate(Poly f){
  30. return f.a * f.n;
  31. }
  32.  
  33. int main(){
  34. FAST;
  35. int n;
  36. cin >> n;
  37. FOR(i , 1 , n) cin >> f[i].a;
  38. FOR(i , 1 , n) cin >> f[i].n;
  39. double x;
  40. cin >> x;
  41. int cnt = 0;
  42. FOR(i , 1 , n){
  43. cnt += (f[i].a == 0);
  44. if(f[i].a == 0) continue;
  45. if(f[i].n == 0){
  46. cout << f[i].a << " + ";
  47. continue;
  48. }
  49.  
  50. if(i == n){
  51. if(f[i].a == 1){
  52. cout << "x^" << f[i].n;
  53. continue;
  54. }
  55. else if(f[i].n == 1){
  56. cout << f[i].a << "x";
  57. continue;
  58. }
  59. else{
  60. cout << f[i].a << "x^" << f[i].n;
  61. continue;
  62. }
  63. }
  64.  
  65. if(f[i].n == 1){
  66. if(f[i].a > 1) cout << f[i].a << "x" << " + ";
  67. else cout << "x" << " + ";
  68. continue;
  69. }
  70.  
  71.  
  72. if(f[i].a == 1){
  73. if(f[i].n > 1) cout << "x^" << f[i].n << " + ";
  74. else cout << "x" << " + ";
  75. continue;
  76. }
  77.  
  78. cout << f[i].a << "x^" << f[i].n << " + ";
  79. }
  80.  
  81. if(cnt != n) cout << "\n";
  82.  
  83. double res = 0;
  84. FOR(i , 1 , n){
  85. res += f[i].a * binpow(x , f[i].n);
  86. }
  87.  
  88. cout << res << "\n";
  89.  
  90. FOR(i , 1 , n){
  91. if(f[i].a == 0) continue;
  92. if(f[i].n == 0) continue;
  93.  
  94. if(i == n){
  95. if(f[i].n == 1){
  96. cout << derivate(f[i]);
  97. continue;
  98. }
  99. else{
  100. cout << derivate(f[i]) << "x^" << f[i].n - 1;
  101. continue;
  102. }
  103. }
  104.  
  105. if(f[i].n == 1){
  106. cout << derivate(f[i]) << " + ";
  107. continue;
  108. }
  109.  
  110. if(f[i].n == 2){
  111. cout << derivate(f[i]) << "x" << " + ";
  112. continue;
  113. }
  114.  
  115. cout << derivate(f[i]) << "x^" << f[i].n - 1 << " + ";
  116. }
  117. }
Success #stdin #stdout 0s 544KB
stdin
Standard input is empty
stdout
0