NewOJ 1464: [蓝桥杯2019初赛]数的分解(水题、暴力)

题目链接:点击这里
在这里插入图片描述
填空题。

为了保证不重复,选定默认顺序为递增。

#include<iostream>
#include<algorithm>
#include<string>
#include<cstdio>
#include<cstring>
#include<cmath>

using namespace std;
typedef long long ll;

bool check(int n)
{
	while(n)
	{
		int tmp = n % 10;
		if(tmp==2||tmp==4)	return false;
		n /= 10;
	}
	return true;
}

int main()
{
	int ans = 0;
	for(int i = 1; i < 2019; ++i)
	{
		if(check(i))
		{
			for(int j = i + 1; j < 2019; ++j)
			{
				if(check(j))
				{
					int k = 2019 - i - j; 	
					if(check(k) && k > j)	ans++;
				}
			}
		}
	}
	
	printf("%d", ans);		//40785
	
	return 0;
}
发布了748 篇原创文章 · 获赞 113 · 访问量 13万+

猜你喜欢

转载自blog.csdn.net/qq_42815188/article/details/104501277