列表

详情


NC229490. Many Littles Make a Mickle

描述

Gather sand to form a tower is a Chinese idiom, whose Pinyin is . It means to pile sand into a pagoda, referring that a little makes a lot. From the fahua Sutra - convenience products.


Suppose the tower has N floors. There are rooms on the floor. Each room can accommodate M people. How many people can the N floor tower accommodate?

输入描述

The first line is a positive integer , indicating that there are T test data.

Next, there are T lines. Each line has two positive integers N 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 N 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)

上一题