gonorth
发表于 2020-11-4 22:29:43
def palin(x):
if str(x) == str(x)[::-1]:
return True
return False
def getp():
list1 =
list2 =
for i in range(100,1000):
for j in range (100,1000):
if palin(i*j):
x = i * j
if x > list1:
list1.pop()
list1.append(x)
if (i + j )> (list2 + list2):
list2.pop()
list2.pop()
list2.append(i)
list2.append(j)
print (list2)
print (list1)
getp()
xg-sco
发表于 2020-12-26 23:19:49
#include <stdio.h>
#define NUM 1000
int main ()
{
int max_1 = -1024, max_2 = 0, max_3 = 0;
int multiply, i, j;
int a, b, c, d, e, f;
for (i = 900; i < NUM; i++)
{
for (j = 900; j < i; j++)
{
multiply = i * j;
a = multiply / 100000 % 10;
b = multiply / 10000 % 10;
c = multiply / 1000 % 10;
d = multiply / 100 % 10;
e = multiply / 10 % 10;
f = multiply % 10;
if (a == f && b == e && c == d)
{
if (multiply > max_1)
{
max_1 = multiply;
max_2 = j;
max_3 = i;
}
// printf("%d = %d * %d\n", multiply, i, j);
}
}
}
printf("%d = %d * %d\n", max_1, max_2, max_3);
return 0;
}
a1351468657
发表于 2021-3-6 13:23:21
#include <stdio.h>
#include <math.h>
main()
{
int i, j, k, num, mun = 0, temp;
for (i = 998001; i > 10000; i--)
{
num = i;
for (j = 5; j >= 0; j--)
{
temp = num % 10;
mun += (temp * pow(10, j));
num = (num - temp) / 10;
}
if (mun == i)
{
for (k = 999; k > 100; k--)
{
if (mun % k == 0)
{
temp = mun / k;
if ((temp / 1000) == 0)
{
goto Label;
}
}
}
}
mun = 0;
}
Label:printf("%d = %d * %d\n", mun, k, mun / k);
}
永恒的蓝色梦想
发表于 2021-3-10 22:45:29
本帖最后由 永恒的蓝色梦想 于 2021-3-10 22:50 编辑
constexpr bool isPalindrome(unsigned int val)noexcept {
unsigned int copy = val, rev = 0;
while (val) {
rev += val;
val /= 10;
rev -= val * 10;
}
return !(copy ^ rev);
}
hjg
发表于 2021-4-1 21:11:54
无名侠 发表于 2015-7-9 14:41
难点应该就是判断是否为回文了。
我用的方法有些歪门邪道,利用字符串来判断,不过效率还行。
然后就是三 ...
906609
hjg
发表于 2021-4-2 08:56:15
906609
public static void main(String[] args) {
System.out.println(largestPalindrome(3));
}
public static int largestPalindrome(int n) {
if(n == 1) return 9;
//计算给定位数的最大值
long max = (long)Math.pow(10,n) - 1;
//从max - 1开始循环,原因见上文
for(long i = max - 1; i > max / 10; i--){
//1. 构造回文数
String s1 = String.valueOf(i);
long rev = Long.parseLong(s1 + new StringBuilder(s1).reverse().toString());
//2. 检验该回文数能否由给定的数相乘得到
for(long x = max; x * x >= rev; x --){
if(rev % x == 0) return (int)(rev );
}
}
return -1;
}
酷爱语言的小白
发表于 2021-4-26 14:20:34
def number(x):
y = 10**x-1
z = 10**(x-1)
for i in range(y**2,z**2,-1):
j = int(str(i)[::-1])
if i == j:
for m in range(y,z,-1):
if i% m == 0:
n = int(i/ m)
if n in range(z,y):
return m, n, i
print(number(3))
Kuri5u
发表于 2021-5-3 20:51:40
#由于909*902=819918,我们从这里开始。
target=[]
for a in range(909,1000):
for b in range(902,1000):
r=a*b#r for result
#显然所求的数为六位数
if (str(r)==str(r))and (str(r)==str(r)) and (str(r)==str(r)):
target.append(r)
print(target)
结果为:
michaelwatson
发表于 2021-5-6 16:53:12
本帖最后由 michaelwatson 于 2021-5-6 16:55 编辑
好啊
中国好青年
发表于 2021-5-18 15:42:52
a = []
for m in range(99,1000):
for n in range(99,1000):
i = m*n
b = str(i)
c = list(b)
if c[::-1] == c:
a.append(i)
print(max(a))
答案906609
13425808254
发表于 2021-7-15 19:53:36
a = 0
b = ''
for i in range(100,1000):
for o in range(100,1000):
if str(i*o) == str(i*o)[::-1]:
if i*o > a:
a = i*o
b = "(" + str(i) + ',' + str(o) + ')'
else:
continue
else:
continue
else:
print(a)
print(b)
卢本伟牛逼
发表于 2021-8-8 22:52:51
#include <stdio.h>
int count;
int ispalindrome(int n)
{
int result = 0;
int value = n;
while(n!=0)
{
count++;
result = (n%10) + result * 10;
n = n / 10;
}
return (result == value)?1:0;
}
int main(void)
{
int max_i, max_j;
int max;
int i=999,j=999;
for(i=999;i>=100;i--)
{
for(j=999;j>=100;j--)
{
if (i<max_i && j < max_j) break; //不加这段count = 4718843加上count = 500591
if (ispalindrome(i * j)){
if (i * j > max){
max_i = i;
max_j = j;
max = (i * j > max)?i * j:max;
}
}
}
}
printf("%d * %d = %d\n", max_i, max_j, max);
printf("count = %d\n", count);
return 0;
}
鱼塘里的鱼儿
发表于 2021-10-6 09:15:32
#include <iostream>
using namespace std;
int main()
{
int a,b,c;
for(int i=100;i<=999;i++)
{
a=i%10;
b=i/10%10;
c=i/100;
if(a==c)
cout<<i<<endl;
}
return 0;
}
//C++写的
ft215378
发表于 2021-10-8 16:18:07
#最大的两个三位数乘积构成的回文数
#检查是否回文
def check(n, start, end):
if start > end:
return 1
else:
return check(n, start+1, end-1) if n == n else 0
#提取数字计算
result = []
res = []
for a in range(100, 999):
for b in range(500,999):
string = str(a * b)
length = len(string) - 1
if check(string, 0, length):
result.append(int(string))
if max(result) == int(string):
res.append((a,b))
print(res[-1])
番杰
发表于 2021-10-27 13:42:09
本帖最后由 番杰 于 2021-10-27 13:58 编辑
#include<stdio.h>
int mian(void)
{
int t1,t10,t100,temp;
int a,b,max;
int flag = 0 ;
for(int i = 997799;i>10000;i--)//从997799开始,是因为它是998001(999*999)之下最大的回文数
{
if(i>100000)//六位回文数
{
t1 = i % 10;
t10 = (i % 100) / 10;
t100 = (i % 1000) /100;
temp = (t1 * 100) + (t10 * 10) + t100;
if(temp == (i/1000)) //判断是否是回文数
{
for(int j = 999;j>=100;j--)
{
if(i % j == 0)
{
if(j > 99 && j < 1000)
{
a = j ;
b = i / j ;
max = i;
flag = 1;
break;
}
}
}
if(flag == 1)
break;
}
}
else //五位回文数
{
t1 = i % 10;
t10 = (i % 100) / 10;
temp = (t1 * 100) + (t10 * 10) ;
if(temp == (i/1000))
{
for(int j = 999;j>=100;j--)
{
if(i % j == 0)
{
if(j > 99 && j < 1000)
{
a = j ;
b = i / j ;
max = i;
flag = 1;
break;
}
}
}
if(flag == 1)
break;
}
}
printf("%d = %d + %d",c,a,b);
return 0 ;
}
learner-ray
发表于 2021-11-13 02:10:38
最大回文数为:993 * 913 = 906609
#include<stdio.h>
int main(void)
{
int i, j;
int mul, lum, max = 0;
int k, buf;
int a, b;
for (i = 999; i > 100; i--)
{
for (j = 999; j > 100; j--)
{
lum = 0;
mul = i * j;
buf = mul;
while (mul)
{
k = mul % 10;
mul = mul / 10;
lum = lum * 10 + k;
}
if (lum == buf)
{
if (lum > max)
{
max = lum;
a = i; b = j;
}
}
}
}
printf("最大回文数为:%d * %d = %d\n", a, b, max);
return 0;
}
learner-ray
发表于 2021-11-13 02:43:37
i初始化为2*3*5*7*11*13*17*19是抄的评论大神的,我自己写的是i初始化为21,循环i++;运行了2秒多。大神的方法只运行了0.2秒。快了十倍。
结果:最小能被1-20 中每个数整除的正整数是232792560
#include<stdio.h>
int main(void)
{
int i, k, j;
int count;
i = k = 2*3*5*7*11*13*17*19;
while (1)
{
count = 0;
for (j = 1; j < 21; j++)
{
if (i % j == 0)
{
count++;
}
else
{
break;
}
}
if (count == 20)
{
printf("最小能被1-20 中每个数整除的正整数是%d\n", i);
break;
}
else
{
i = i + k;
}
}
return 0;
}
guosl
发表于 2022-1-2 11:30:18
/*
找出由两个3位数相乘得到的最大回文乘积。
答案:906609
耗时:0.00836184秒(单线程)
0.00248691秒(八线程)
*/
#include <iostream>
#include <algorithm>
#include <omp.h>
using namespace std;
inline bool ChkPalindrome(int k)
{
int x = k, y = 0;
while (x > 0)
{
y = 10 * y + x % 10;
x = x / 10;
}
return (y == k);
}
int main(void)
{
double t = omp_get_wtime();
int x = 0;
#pragma omp parallel for reduction(max:x)
for (int i = 100; i <= 999; ++i)
{
for (int j = i; j >= 100; --j)
{
int a = i * j;
if (ChkPalindrome(a))
{
x = max(x, a);
break;
}
}
}
t = omp_get_wtime() - t;
cout << x << endl << "耗时:" << t << "秒" << endl;
return 0;
}
mathtimes
发表于 2022-1-27 14:25:31
本帖最后由 mathtimes 于 2022-1-27 14:28 编辑
#include <cstdio>
bool isPalindromicNumber(int num)
{
char bits = {0};
int len = 0;
for(;num>0;len++)
{
bits = num%10;
num /= 10;
}
for(int i=0;i<len/2+1;i++)
if(bits!=bits)
return false;
return true;
}
int main()
{
int max = 0;
for(int i=100;i<1000;i++)
for(int j=100;j<1000;j++)
if(isPalindromicNumber(i*j)&&i*j>max)
max =i*j;
printf("%d",max);
}
jerryxjr1220
发表于 2022-2-22 22:56:22
package main
import (
"fmt"
"time"
)
//题目4:
//
//一个回文数指的是从左向右和从右向左读都一样的数字。最大的由两个两位数乘积构成的回文数是 9009 = 91 * 99。
//
//找出最大的有由个三位数乘积构成的回文数。
func main() {
t := time.Now()
var nums int
index := 0
for a := 100; a < 1000; a++ {
for b := 100; b < 1000; b++ {
c := a * b
str := fmt.Sprintf("%d", c)
flag := true
length := len(str) - 1
for i := 0; i < length; i++ {
if str != str {
flag = false
break
}
}
if flag {
nums = c
index++
}
}
}
max := 0
for i := 0; i < len(nums); i++ {
if nums > max {
max = nums
}
}
fmt.Println(max)
tt := time.Now()
fmt.Println("耗时:", (tt.Nanosecond()-t.Nanosecond())/1e6, "ms")
}
输出:
GOROOT=C:\Program Files\Go #gosetup
GOPATH=C:\Users\Administrator\go #gosetup
"C:\Program Files\Go\bin\go.exe" build -o C:\Users\Administrator\AppData\Local\Temp\GoLand\___10go_build_GoProject_src.exe C:\Users\Administrator\Documents\GoProject\src\Euler04.go #gosetup
C:\Users\Administrator\AppData\Local\Temp\GoLand\___10go_build_GoProject_src.exe
906609
耗时: 47 ms
进程 已完成,退出代码为 0