Little Gyro and Sets(第二届中国计量大学ACM程序设计竞赛个人赛)

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("%lld\n", sumb-suma);
    }
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值