第十四届蓝桥杯三月真题刷题训练——第 7 天(3.10)

杨枝 杨枝 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区

第一题主要是判断回文,那个三角不三角都不重要了
 

#include <bits/stdc++.h>
#define mpr make_pair
#define pb push_back
#define fi first
#define se second
#define endl '\n'

using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
const int INF = 0x3f3f3f3f;
const int N  = 6e3 + 10;

bool check(int n)
{
	string val = to_string(n);
	string tmp = val;
	reverse(tmp.begin(),tmp.end());
	if(tmp == val) return true;
	else return false;
}

void solve(){
//	cout << 363* 364/2;
	
//	cout << (20220514 > (N*(N+1)/2));
	
	for(int i = N;i < INF;i++)
	{
		int num = i*(i+1)/2;
		if(num > 20220514 && check(num))
		{
			cout << num;
			return;
		}
	}
	
}

void run()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
}

int main() {
	run();
	int t;
	t = 1;
	
	while(t--) {
		solve();
	}

	return 0;
}

 

 

第二题学一个分解质因数

#include <bits/stdc++.h>
#define mpr make_pair
#define pb push_back
#define fi first
#define se second
#define endl '\n'

using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
const int INF = 0x3f3f3f3f;
const int N  = 1e5 + 10;
 
bool get_ans(int n)
{
	int cnt = 0;
	for(int i = 2;i * i <= n;i++)
	{
		if(n % i == 0)
		{
			while(n%i == 0)
			{
				n /= i;
				cnt ++; 
			}
		}
	}
	if(n != 1) cnt ++;
	if(cnt == 12) return true;
	else return false;
}
void solve(){
	int ans = 0;
	for(int i = 2333333;i <= 23333333;i++)
	{
		if(get_ans(i)) ans ++;	
	}	
	cout << ans;
}

void run()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
}

int main() {
	run();
	int t;
	t = 1;
	
	while(t--) {
		solve();
	}

	return 0;
}

 

...全文
评论
收藏 已收藏
分享
返回顶部
杨枝
杨枝 新星创作者: C/C++技术领域 新星创作者: C/C++技术领域
高校算法学习社区 51,730 成员 6,062 内容