题解:P15430 [蓝桥杯 2025 国 Python B] 等差数列计数

· · 题解

按公差分类讨论(目前只考虑递增)。

公差为1的:(1,2,3)、(2,3,4)、\dots、(2023,2024,2025),共2023个。

公差为2的:(1,3,5)、(2,4,6)、\dots、(2021,2023,2025),共2021个。

公差为3的:(1,4,7)、(2,5,8)、\dots、(2019,2022,2025),共2019个。

以后,公差每增加1,个数就减少2个。总共有1+3+5+\dots+2023=1012^2=1024144个。

但是!(1,2,3)和(3,2,1)是不同的等差数列!!!

所以真正的答案是1024144\times 2=2048288。

#include<bits/stdc++.h>
using namespace std;

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cout<<"2048288";
    return 0;
}