A. 幸运数
小蓝认为如果一个数含有偶数个数位,并且前面一半的数位之和等于后面一半的数位之和,则这个数是他的幸运数字。例如 23142314 是一个幸运数字,因为它有 44 个数位,并且 2+3=1+42+3=1+4。现在请你帮他计算从 11 至 100000000100000000 之间共有多少个不同的幸运数字。
暴力枚举
代码如下:
#include<bits/stdc++.h>
#define LL_int 128
using namespace std;
const int N = 10000000;
int len;
int n,m;
bool st[N];
int ans=0;
signed main(){
std::ios::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
for(int i=1;i<=100000000 ;i++){
if(i%2==0){
int a=i/1000;
int b=i/100%10;
int c=i%100/10;
int d=i%10;
if(a+b==c+d){
ans++;
}
}
}
cout<<ans;
return 0;
}