其他分享
首页 > 其他分享> > Project Euler 004

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;
}

标签:10,nx,return,int,res,long,Project,004,Euler
来源: https://www.cnblogs.com/akoasm/p/15832817.html