博客园 首页 私信博主 显示目录 隐藏目录 管理 动画

Project Euler 004

T4 最大三位数乘积回文数

#include <bits/stdc++.h>
using namespace std;
#define int long long

bool judge(int x) {
	int nx = x;
	int t = x;
	int res = 0;
	while(t) {
		res = res * 10 + t % 10;
		t /= 10;
	}
	if(res == nx) return 1;
	else return 0;
}
int res;

void dfs(int ans,int now) {
	//cout << ans << endl;
	if(now == 2) {
		if(judge(ans))
			res = max(res,ans);
		return;
	}
	else {
		for(int i = 100;i <= 999;i ++) {
			ans = ans * i;
			dfs(ans,now + 1);
			ans /= i;
		}
	}
}

		
signed main () {
	dfs(1,0);
	cout << res << endl;
	return 0;
}
posted @ 2022-01-22 12:22  Allorkiya  阅读(22)  评论(0编辑  收藏  举报