A - Math Problem(签到题)

版权声明:Andy https://blog.csdn.net/Alibaba_lhl/article/details/81976656

Sample Input

2
2 1
3 5
3 2
1 2 3

 Sample Output

8
2

Source::Click here

题意

题目很明确了,给n个整数和一个整数k,对每个数除以k后的数值进行向下取整,然后对其求和。

                                                                                                                                                                                                                   

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <functional>
#include <algorithm>
#define _USE_MATH_DEFINES
using namespace std;
typedef long long ll;
const int MAXN = 200000+5;

int main()
{
    int T;
    cin>> T;
    while(T--)
    {
        int n, k, x;
        cin>> n >> k;
        ll sum = 0;
        for(int i=1; i<=n; i++)
        {
            scanf("%d",&x);
            sum = sum + x / k;
        }
        printf("%lld\n",sum);
    }

    return 0;
}

猜你喜欢

转载自blog.csdn.net/Alibaba_lhl/article/details/81976656