projecteuler---->problem=4----Largest palindrome product

title:

Largest palindrome product

Problem 4

A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91
99.

Find the largest palindrome made from the product of two 3-digit numbers.

翻译;

假如一个数前后掉转后还是同一个数的话,那个数就叫做「回文数」。由两个二位数的积构成的最大回文数是9009 = 91 × 99。

请找出由两个三位数的积构成的最大回文数。

解答:

def isOk(a):
	n=0
	b=[0]*100
	while a>0:
		b[n]=a%10
		a /= 10
		n += 1
	for i in range(n//2):
		if b[i]!=b[n-i-1]:
			return False
	return True

m=0
for i in range(100,999):
	for j in range(100,999):
		if isOk(i*j) :
			if i*j > m:
				m = i*j;

print m

projecteuler---->problem=4----Largest palindrome product

时间: 2024-10-27 13:47:17

projecteuler---->problem=4----Largest palindrome product的相关文章

Largest palindrome product

problem 4:Largest palindrome product 题意:求由三位数和三位数之积构成的最大回文数字 代码如下: 1 #ifndef PRO4_H_INCLUDED 2 #define PRO4_H_INCLUDED 3 4 namespace pro4{ 5 bool ispalindromic(int n){ 6 int a[6],k=0; 7 while(n){ 8 a[k++]=n%10; 9 n/=10; 10 } 11 for(int i=0;i<k/2;++i)

PE 4 Largest palindrome product(最大回文)

题目 A palindromic number reads the same both ways. The largest palindrome made from the product of two 2-digit numbers is 9009 = 91 × 99. Find the largest palindrome made from the product of two 3-digit numbers. https://projecteuler.net/problem=1 分析 题

【easy】479. Largest Palindrome Product

Find the largest palindrome made from the product of two n-digit numbers Since the result could be very large, you should return the largest palindrome mod 1337. Example: Input: 2 Output: 987 Explanation: 99 x 91 = 9009, 9009 % 1337 = 987 Note:The ra

479. Largest Palindrome Product

问题描述: Find the largest palindrome made from the product of two n-digit numbers. Since the result could be very large, you should return the largest palindrome mod 1337. Example: Input: 2 Output: 987 Explanation: 99 x 91 = 9009, 9009 % 1337 = 987 Note

LeetCode 479 - Largest Palindrome Product - Hard ( Python)

Find the largest palindrome made from the product of two n-digit numbers. Since the result could be very large, you should return the largest palindrome mod 1337. Example: Input: 2 Output: 987 Explanation: 99 x 91 = 9009, 9009 % 1337 = 987 Note: The

Project-Euler problem 1-50

最近闲的做了下Project Euler 上的题目,前面50题都比较简单,简单总结下.代码一般是Python和C/C++的 用Python 做这些题目简直是酸爽啊 一下代码可能不一定是我的,因为不知道论坛里面的回复不是永久的,所以我的代码有的丢了,可能找个和我的意思相近的代码.题目翻译是从 欧拉计划 | Project Euler 中文翻译站上面Copy 的表告我. Problem 1  Multiples of 3 and 5 10以下的自然数中,属于3和5的倍数的有3,5,6和9,它们之和是

Project Euler:Problem 11 Largest product in a grid

In the 20×20 grid below, four numbers along a diagonal line have been marked in red. 08 02 22 97 38 15 00 40 00 75 04 05 07 78 52 12 50 77 91 08 49 49 99 40 17 81 18 57 60 87 17 40 98 43 69 48 04 56 62 00 81 49 31 73 55 79 14 29 93 71 40 67 53 88 30

[LeetCode&amp;Python] Problem 409. Longest Palindrome

Given a string which consists of lowercase or uppercase letters, find the length of the longest palindromes that can be built with those letters. This is case sensitive, for example "Aa" is not considered a palindrome here. Note:Assume the lengt

[Atcoder Code Festival 2017 Qual B Problem F]Largest Smallest Cyclic Shift

题目大意:给你\(A\)个a,\(B\)个b,\(C\)个c,要你构造一个字符串,使它的最小循环表示法最大.求这个表示法.解题思路:不知道怎么证,但把a.b.c当做单独的字符串扔进容器,每次把字典序最小的和字典序最大的两个字符串合并就是答案.容器用multiset即可. C++ Code: #include<cstdio> #include<set> #include<string> using namespace std; multiset<string>