返回题解分享
讨论 / 题解分享/ 帖子详情

特别数的和(编程题) - 题解

n最大才10000,一共整除才5次,直接暴力。

#include<bits/stdc++.h>

using namespace std;

bool sentence(int num)
{
	for(int i = 1; i <= 5; i++){
		int n;
		if(num > 0){
			n = num % 10;
			num /= 10;
		}
		if(n == 2 || n == 0 || n == 1 || n == 9){
			return true;
		}
	}
	return false;
}
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	int n;
	long long ans = 0;
	
	cin >> n;
	
	for(int i = 1; i <= n; i++){
		if(sentence(i)){
			ans += i;
		}
		
	}
	cout << ans;
	return 0;
}
0 回复 0 转发 0 喜欢 2 阅读
回复 (0)
默认 最新
暂无回复,快来抢沙发!