NC229490. Many Littles Make a Mickle
描述
输入描述
The first line is a positive integer , indicating that there are test data.
Next, there are lines. Each line has two positive integers and , indicating the number of floors of the tower and the number of people that can be accommodated in each room in a test data.
输出描述
Each test data outputs a line containing one positive integer, that is, the total number of people that can be accommodated in the floor tower.
示例1
输入:
2 2 2 3 3
输出:
10 42
C++(clang++ 11.0.1) 解法, 执行用时: 3ms, 内存消耗: 432K, 提交时间: 2022-10-07 20:33:21
#include<iostream> using namespace std; int main(){ int t;cin>>t; while(t--){ int n,m;cin>>n>>m; cout<<n*(n+1)*(2*n+1)/6*m<<endl; } }
pypy3 解法, 执行用时: 72ms, 内存消耗: 21540K, 提交时间: 2022-10-22 19:08:43
for text in range(int(input())): n,m=map(int,input().split()) print(sum(i*i for i in range(1,n+1))*m)
Python3 解法, 执行用时: 40ms, 内存消耗: 4528K, 提交时间: 2022-10-22 09:19:44
t=int(input()) while t: t=t-1 n,m=map(int,input().split()) print(n*(n+1)*(2*n+1)*m//6)