C++三级函数

多天未见,甚是想念

纯粹素数

cpp 复制代码
#include<bits/stdc++.h>
using namespace std;
long long n;
bool hh(int);
int main()
{
	for(int i=1000;i<=3000;i++)
	{
		int a=i%1000;
		int b=i%100;
		int c=i%10;
		if(hh(i)==true&&hh(a)==true&&hh(b)==true&&hh(c)==true){
			cout<<i<<endl;
		}
	}
	return 0;
}
bool hh(int a){
	if(a==1){
		return false;
	}
	if(a==2){
		return true;
	}
	for(int i=2;i*i<=a;i++){
		if(a%i==0){
			return false;
		}
	}
}

求一个三位数

cpp 复制代码
include<bits/stdc++.h>
using namespace std;
int n;
int hs(int);
int main()
{
	int u;
	for(int i=100;i<=999;i++)
	{
		int a=i/100%10;
		int b=i/10%10;
		int c=i/10;
		int d=hs(a);
		int e=hs(b);
		int f=hs(c);
		if(d+e+f==i)
		{
			u=i;
			break;
		}
	}
	cout<<u;
	return 0;
}
int hs(int z){
	int h;
	for(int i=1;i<=z;i++)
	{
		h=h*i;
	}
	return h;
}

亲密数对我尽力了

回文数个数

cpp 复制代码
#include<bits/stdc++.h>
using namespace std;
int n;
void hs(int);
int main()
{
	
	hs();
	return 0;
}
void hs()
{
	int y,h=0,sum=0;
	cin>>n;
	for(int i=0;i<=n;i++)
	{
		int a=i;
		y=i;
		while(a!=0){
			h=h*10+a%10;
			a=a/10;
		}
		if(h==y){
			sum++;
		}
	}
	cout<<sum;
	return;
}

歌德巴赫猜想

相关推荐
宝贝儿好3 小时前
【强化学习实战】第十一章:Gymnasium库的介绍和使用(1)、出租车游戏代码详解(Sarsa & Q learning)
人工智能·python·深度学习·算法·游戏·机器学习
2401_884602276 小时前
程序人生-Hello’s P2P
c语言·c++
weixin_458872616 小时前
东华复试OJ二刷复盘2
算法
Charlie_lll6 小时前
力扣解题-637. 二叉树的层平均值
算法·leetcode
初中就开始混世的大魔王6 小时前
2 Fast DDS Library概述
c++·中间件·信息与通信
MediaTea6 小时前
Python:collections.Counter 常用函数及应用
开发语言·python
爱淋雨的男人6 小时前
自动驾驶感知相关算法
人工智能·算法·自动驾驶
wen__xvn7 小时前
模拟题刷题3
java·数据结构·算法