列表

详情


NC208610. 凑数

描述

现在你有n+1个数:0n。现在你要回答次询问,每次m询问输入一个k,代表从n+1个数中选出k个数求和,问最后的值有几种不同方案?



输入描述

第一行输入n、m

接下来m行输入一个k

输出描述

m行,每行一个答案

示例1

输入:

5   3
1
2
3

输出:

6
9
10

原站题解

import java.util.Scanner;
public class Main {
public static void main(String[] arg) {
Scanner scanner = new Scanner(System.in);
// todo
}
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

C++14(g++5.4) 解法, 执行用时: 234ms, 内存消耗: 10976K, 提交时间: 2020-07-04 14:50:33

#include<bits/stdc++.h>
using namespace std;
int main()
{
long long int a,b;
scanf("%lld %lld",&a,&b);
while(b--)
{
long int t;
scanf("%lld",&t);
long long int ans=((a+(a-t+1))*t/2)-((0+0+t-1)*t/2)+1;
printf("%lld\n",ans);
}
}

C(clang 3.9) 解法, 执行用时: 180ms, 内存消耗: 10968K, 提交时间: 2020-07-16 12:54:16

#include<stdio.h>
int main(void){
int n,m,b;
scanf("%d%d",&n,&m);
for(b=0;b<m;b++){
long k;
scanf("%ld",&k);
long min=k*(k-1)/2,max=k*n-k*(k-1)/2;
printf("%ld\n",(max-min+1));
}
}

C++11(clang++ 3.9) 解法, 执行用时: 292ms, 内存消耗: 10980K, 提交时间: 2020-07-04 14:47:47

#include<bits/stdc++.h>
using namespace std;
int main(){
int n,m;cin>>n>>m;
while(m--){
int k;
scanf("%d",&k);
printf("%lld\n",(1ll*k*(n-k+1)+1));
}
return 0;
}

上一题