Xem thảo luận
Cải thiện bài viết
Lưu bài viết
Xem thảo luận
Cải thiện bài viết
Lưu bài viết
Đọc
Input : n = 5 Output : 225 13 + 23 + 33 + 43 + 53 = 225 Input : n = 7 Output : 784 13 + 23 + 33 + 43 + 53 + 63 + 73 = 784
Python3
Python3
Bàn luận
In tổng của chuỗi 13 + 23 + 33 + 43 +. Ví dụ:
def
sumOfSeries[n]:
sum
2250
2251
2253
2254
2255
2256
2257
2258
2259
For n = 5 sum by formula is [5*[5 + 1 ] / 2]] ^ 2 = [5*6/2] ^ 2 = [15] ^ 2 = 225 For n = 7, sum by formula is [7*[7 + 1 ] / 2]] ^ 2 = [7*8/2] ^ 2 = [28] ^ 2 = 7840__18
For n = 5 sum by formula is [5*[5 + 1 ] / 2]] ^ 2 = [5*6/2] ^ 2 = [15] ^ 2 = 225 For n = 7, sum by formula is [7*[7 + 1 ] / 2]] ^ 2 = [7*8/2] ^ 2 = [28] ^ 2 = 7842
For n = 5 sum by formula is [5*[5 + 1 ] / 2]] ^ 2 = [5*6/2] ^ 2 = [15] ^ 2 = 225 For n = 7, sum by formula is [7*[7 + 1 ] / 2]] ^ 2 = [7*8/2] ^ 2 = [28] ^ 2 = 7843
sum
For n = 5 sum by formula is [5*[5 + 1 ] / 2]] ^ 2 = [5*6/2] ^ 2 = [15] ^ 2 = 225 For n = 7, sum by formula is [7*[7 + 1 ] / 2]] ^ 2 = [7*8/2] ^ 2 = [28] ^ 2 = 7840
2250
For n = 5 sum by formula is [5*[5 + 1 ] / 2]] ^ 2 = [5*6/2] ^ 2 = [15] ^ 2 = 225 For n = 7, sum by formula is [7*[7 + 1 ] / 2]] ^ 2 = [7*8/2] ^ 2 = [28] ^ 2 = 7847
For n = 5 sum by formula is [5*[5 + 1 ] / 2]] ^ 2 = [5*6/2] ^ 2 = [15] ^ 2 = 225 For n = 7, sum by formula is [7*[7 + 1 ] / 2]] ^ 2 = [7*8/2] ^ 2 = [28] ^ 2 = 7848
For n = 5 sum by formula is [5*[5 + 1 ] / 2]] ^ 2 = [5*6/2] ^ 2 = [15] ^ 2 = 225 For n = 7, sum by formula is [7*[7 + 1 ] / 2]] ^ 2 = [7*8/2] ^ 2 = [28] ^ 2 = 7847
For n = 5 sum by formula is [5*[5 + 1 ] / 2]] ^ 2 = [5*6/2] ^ 2 = [15] ^ 2 = 225 For n = 7, sum by formula is [7*[7 + 1 ] / 2]] ^ 2 = [7*8/2] ^ 2 = [28] ^ 2 = 7848__
2258
2259
225
3 sum
225
2255
2250
2257efficient solution is to use direct mathematical formula which is [n [ n + 1 ] / 2] ^ 2
For n = 5 sum by formula is [5*[5 + 1 ] / 2]] ^ 2 = [5*6/2] ^ 2 = [15] ^ 2 = 225 For n = 7, sum by formula is [7*[7 + 1 ] / 2]] ^ 2 = [7*8/2] ^ 2 = [28] ^ 2 = 784
Python3
Python3
Bàn luận
In tổng của chuỗi 13 + 23 + 33 + 43 +. Ví dụ:
def
sumOfSeries[n]:
For n = 5 sum by formula is [5*[5 + 1 ] / 2]] ^ 2 = [5*6/2] ^ 2 = [15] ^ 2 = 225 For n = 7, sum by formula is [7*[7 + 1 ] / 2]] ^ 2 = [7*8/2] ^ 2 = [28] ^ 2 = 7843
sum
For n = 5 sum by formula is [5*[5 + 1 ] / 2]] ^ 2 = [5*6/2] ^ 2 = [15] ^ 2 = 225 For n = 7, sum by formula is [7*[7 + 1 ] / 2]] ^ 2 = [7*8/2] ^ 2 = [28] ^ 2 = 7840
2250
For n = 5 sum by formula is [5*[5 + 1 ] / 2]] ^ 2 = [5*6/2] ^ 2 = [15] ^ 2 = 225 For n = 7, sum by formula is [7*[7 + 1 ] / 2]] ^ 2 = [7*8/2] ^ 2 = [28] ^ 2 = 7847
For n = 5 sum by formula is [5*[5 + 1 ] / 2]] ^ 2 = [5*6/2] ^ 2 = [15] ^ 2 = 225 For n = 7, sum by formula is [7*[7 + 1 ] / 2]] ^ 2 = [7*8/2] ^ 2 = [28] ^ 2 = 7848
For n = 5 sum by formula is [5*[5 + 1 ] / 2]] ^ 2 = [5*6/2] ^ 2 = [15] ^ 2 = 225 For n = 7, sum by formula is [7*[7 + 1 ] / 2]] ^ 2 = [7*8/2] ^ 2 = [28] ^ 2 = 7847
For n = 5 sum by formula is [5*[5 + 1 ] / 2]] ^ 2 = [5*6/2] ^ 2 = [15] ^ 2 = 225 For n = 7, sum by formula is [7*[7 + 1 ] / 2]] ^ 2 = [7*8/2] ^ 2 = [28] ^ 2 = 7848__
2258
2259
Output:
225
2253
sum
How does this formula work? We can prove the formula using mathematical induction. We can easily see that the formula holds true for n = 1 and n = 2. Let this be true for n = k-1.Let the formula be true for n = k-1. Sum of first [k-1] natural numbers = [[[k - 1] * k]/2]2 Sum of first k natural numbers = = Sum of [k-1] numbers + k3 = [[[k - 1] * k]/2]2 + k3 = [k2[k2 - 2k + 1] + 4k3]/4 = [k4 + 2k3 + k2]/4 = k2[k2 + 2k + 1]/4 = [k*[k+1]/2]2
225
5225
0 225
7 Like previous post, we can avoid overflow upto some extent by doing
division first.
Python3
Python3
Bàn luận
In tổng của chuỗi 13 + 23 + 33 + 43 +. Ví dụ:
def
sumOfSeries[n]:
sum
2250
2251
sum
4
0
2253
2254
2255
2256
2257
2258
2259
For n = 5 sum by formula is [5*[5 + 1 ] / 2]] ^ 2 = [5*6/2] ^ 2 = [15] ^ 2 = 225 For n = 7, sum by formula is [7*[7 + 1 ] / 2]] ^ 2 = [7*8/2] ^ 2 = [28] ^ 2 = 7840__18
For n = 5 sum by formula is [5*[5 + 1 ] / 2]] ^ 2 = [5*6/2] ^ 2 = [15] ^ 2 = 225 For n = 7, sum by formula is [7*[7 + 1 ] / 2]] ^ 2 = [7*8/2] ^ 2 = [28] ^ 2 = 7842
def
sumOfSeries[n]:
For n = 5 sum by formula is [5*[5 + 1 ] / 2]] ^ 2 = [5*6/2] ^ 2 = [15] ^ 2 = 225 For n = 7, sum by formula is [7*[7 + 1 ] / 2]] ^ 2 = [7*8/2] ^ 2 = [28] ^ 2 = 7843
sum
For n = 5 sum by formula is [5*[5 + 1 ] / 2]] ^ 2 = [5*6/2] ^ 2 = [15] ^ 2 = 225 For n = 7, sum by formula is [7*[7 + 1 ] / 2]] ^ 2 = [7*8/2] ^ 2 = [28] ^ 2 = 7840
2250
For n = 5 sum by formula is [5*[5 + 1 ] / 2]] ^ 2 = [5*6/2] ^ 2 = [15] ^ 2 = 225 For n = 7, sum by formula is [7*[7 + 1 ] / 2]] ^ 2 = [7*8/2] ^ 2 = [28] ^ 2 = 7847
For n = 5 sum by formula is [5*[5 + 1 ] / 2]] ^ 2 = [5*6/2] ^ 2 = [15] ^ 2 = 225 For n = 7, sum by formula is [7*[7 + 1 ] / 2]] ^ 2 = [7*8/2] ^ 2 = [28] ^ 2 = 7848
For n = 5 sum by formula is [5*[5 + 1 ] / 2]] ^ 2 = [5*6/2] ^ 2 = [15] ^ 2 = 225 For n = 7, sum by formula is [7*[7 + 1 ] / 2]] ^ 2 = [7*8/2] ^ 2 = [28] ^ 2 = 7847
For n = 5 sum by formula is [5*[5 + 1 ] / 2]] ^ 2 = [5*6/2] ^ 2 = [15] ^ 2 = 225 For n = 7, sum by formula is [7*[7 + 1 ] / 2]] ^ 2 = [7*8/2] ^ 2 = [28] ^ 2 = 7848__
2258
2259
Output:
225
225
3 sum
Finding cube sum of first n natural numbers using built-in function pow[]. The pow[] function finds the cube of a number by giving the values of i and number. ex: pow[i,3].
Python3
22507
2250
2257
22523
2250
2251
2255
2250
2257
22523
2250
22523
For n = 5 sum by formula is [5*[5 + 1 ] / 2]] ^ 2 = [5*6/2] ^ 2 = [15] ^ 2 = 225 For n = 7, sum by formula is [7*[7 + 1 ] / 2]] ^ 2 = [7*8/2] ^ 2 = [28] ^ 2 = 7840
22541
22542
22543
2253
2258
22546
Đầu ra:
Làm thế nào để bạn tìm thấy khối lập phương của một số trong Python?
Chương trình Python để tìm khối của một số..
DEF CUBE [X]:.
trả lại x * x * x ..
n = int [input ["Nhập số:"]].
Cube1 = khối lập phương [n].
in ["khối lập phương của {0} = {1}". định dạng [n, khối1]].
Làm thế nào để bạn tìm thấy tổng của hai số trong Python?
Làm thế nào để thêm hai số trong Python..
❮ Trước Sau ❯.
Thí dụ.x = 5. y = 10. in [x + y] tự mình thử ».
Thí dụ.x = input ["loại A số:"] y = input ["loại số khác:"] sum = int [x] + int [y] in ["tổng là:", sum] tự mình thử ».
❮ Trước Sau ❯.
Hai cách để tìm tổng của hai khối là gì?
Tổng hoặc sự khác biệt của hai khối có thể được tính vào một sản phẩm của một nhị thức lần nhị thức một bộ ba.Nghĩa là, x3+y3 = [x+y] [x2 - xy+y2] và x3 - y3 = [x - y] [x2+xy+y2].factored into a product of a binomial times a trinomial. That is, x3+y3=[x+y][x2−xy+y2] and x3−y3=[x−y][x2+xy+y2] .
Làm thế nào để bạn viết 2 khối trong Python?
Để lập khối một số trong Python, cách dễ nhất là tự nhân số ba lần.Chúng ta cũng có thể sử dụng hàm pow [] từ mô -đun toán học để lập khối một số.Cuối cùng, chúng ta có thể tìm thấy khối lập phương của một số trong Python với toán tử số mũ được tích hợp **.multiply the number by itself three times. We can also use the pow[] function from the math module to cube a number. Finally, we can find the cube of a number in Python with the built in exponentiation operator **.