Little Gyro and Sets(第二届中国计量大学ACM程序设计竞赛个人赛)
链接:https://ac.nowcoder.com/acm/contest/3190/B
来源:牛客网

示例1
输入
3
3 5
2 10
3 16
输出
9
-5
46
说明
For the first sample, after these operations, A = < 3 >, B = < 1, 2, 4, 5 >, and the answer is 9.
For the second sample, after these operations, A = < 2, 4, 6, 8, 10 >, B = < 1, 3, 5, 7, 9 >, and the answer is -5.
本题是个数学题。B数组是以n为公差的等差数列,我们只需要求改等差数列的前m/n项和,再用首项加末项乘以项数除以二减去B数组和,即得到A数组的和,最后再用B数组和减去A数组和即可得到答案。
#include <iostream>
#include <cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std
int main()
{
long long int T
scanf("%lld", &T)
while (T--)
{
long long int a, b
long long int suma, sumb
suma = sumb = 0
scanf("%lld %lld", &a, &b)
long long int q = b / a
suma = q * a + (q * (q - 1) * a) / 2
sumb = (1 + b) * b / 2 - suma
printf("%lldn", sumb-suma)
}
return 0
}





Comments NOTHING