跳到正文

题解

题解:P12132 [蓝桥杯 2025 省 B] 可分解的正整数

deng2013约 1 分钟
原文
文章信息与版本

文章信息

收录
2025年12月12日
更新
2025年12月12日
篇幅
约 1 分钟
题目
P12132

版本

  1. v1当前

题目思路

对于每个的 xx , 我们可以把它分解为序列

[1−x,2−x,...,0,...,x−1,x][1−x,2−x,...,0,...,x−1,x] 。

可以发现 (1−x)+(2−x)+...+0+...+(x−1)=0(1-x)+(2-x)+...+0+...+(x-1) = 0 ,0+x=x0 + x = x。

因为序列长度必须要大于等于 3 ,所以当 x=1x=1 时 ,序列为 [1,2][1,2] , 长度为 2 ,小于 3 ,不符合条件。

结论

所有不等于 1 的数都符合条件。

code

C++
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    int ans=0;
    while(n--){
        int x;
        cin>>x;
        if(x!=1) ans++;//不是1,ans就加1
    }
    cout<<ans;
    return 0;
}
原文