479 Largest Palindrome Product 最大回文数乘积
你需要找到由两个 n 位数的乘积组成的最大回文数。
由于结果会很大,你只需返回最大回文数 mod 1337得到的结果。
示例:
输入: 2
输出: 987
解释: 99 x 91 = 9009, 9009 % 1337 = 987
说明:
n 的取值范围为 [1,8]。
详见:https://leetcode.com/problems/largest-palindrome-product/description/
C++:
class Solution {
public:
int largestPalindrome(int n)
{
int upper = pow(10, n) - 1, lower = upper / 10;
for (int i = upper; i > lower; --i)
{
string t = to_string(i);
long p = stol(t + string(t.rbegin(), t.rend()));
for (long j = upper; j * j > p; --j)
{
if (p % j == 0)
{
return p % 1337;
}
}
}
return 9;
}
};
参考:http://www.cnblogs.com/grandyang/p/7644725.html
479 Largest Palindrome Product 最大回文数乘积的更多相关文章
- [LeetCode] Largest Palindrome Product 最大回文串乘积
Find the largest palindrome made from the product of two n-digit numbers. Since the result could be ...
- Java实现 LeetCode 479 最大回文数乘积
479. 最大回文数乘积 你需要找到由两个 n 位数的乘积组成的最大回文数. 由于结果会很大,你只需返回最大回文数 mod 1337得到的结果. 示例: 输入: 2 输出: 987 解释: 99 x ...
- Leetcode 479.最大回文数乘积
最大回文数乘积 你需要找到由两个 n 位数的乘积组成的最大回文数. 由于结果会很大,你只需返回最大回文数 mod 1337得到的结果. 示例: 输入: 2 输出: 987 解释: 99 x 91 = ...
- [Swift]LeetCode479. 最大回文数乘积 | Largest Palindrome Product
Find the largest palindrome made from the product of two n-digit numbers. Since the result could be ...
- 【easy】479. Largest Palindrome Product
Find the largest palindrome made from the product of two n-digit numbers Since the result could be v ...
- palindrome number(回文数)
Determine whether an integer is a palindrome. Do this without extra space. Some hints: Could negativ ...
- [Leetcode] Palindrome number 判断回文数
Determine whether an integer is a palindrome. Do this without extra space. click to show spoilers. S ...
- 【LeetCode】9、Palindrome Number(回文数)
题目等级:Easy 题目描述: Determine whether an integer is a palindrome. An integer is a palindrome when it rea ...
- 9. Palindrome Number[E]回文数
题目 Determine whether an integer is a palindrome. An integer is a palindrome when it reads the same b ...
随机推荐
- POJ 2886 Who Gets the Most Candies?(树状数组+二分)
题目链接 注意题目中给的顺序是顺时针的,所以在数组中应该是倒着存的.左就是顺时针,右就是逆时针.各种调试之后,终于A了,很多种情况考虑情况. #include <cstring> #inc ...
- Educational Codeforces Round 9 E. Thief in a Shop NTT
E. Thief in a Shop A thief made his way to a shop. As usual he has his lucky knapsack with him. Th ...
- LCS的几种求法
\(LCS:\) 对于两个长度均为 \(N\) 的数列 \(A\) 和 \(B\) ,存在一个数列 \(C\) 使得 \(C\) 既是 \(A\) 的子序列有事 \(B\) 的子序列,现在需要求这个数 ...
- Codeforces Round #Pi (Div. 2) C. Geometric Progression
C. Geometric Progression time limit per test 1 second memory limit per test 256 megabytes input stan ...
- SDUT OJ 图练习-BFS-从起点到目标点的最短步数 (vector二维数组模拟邻接表+bfs , *【模板】 )
图练习-BFS-从起点到目标点的最短步数 Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^ 题目描述 在古老的魔兽传说中,有两个军团,一个叫天 ...
- HDU4289 Control —— 最小割、最大流 、拆点
题目链接:https://vjudge.net/problem/HDU-4289 Control Time Limit: 2000/1000 MS (Java/Others) Memory Li ...
- apt-get update 问题 及gcc高亮
一 gcc高亮 gcc 高亮有好几种方法. 参考 http://www.cokco.cn/thread-39909-1-1.html 这个教程: (1) git clone https://githu ...
- windows下运行swoole搭建环境
swoole windows环境搭建 swoole框架是一个很神奇很厉害的框架,它弥补了PHP的本身的一些不足之处.其实swoole确切的说是一个使用C语言编写的PHP扩展,并且这个扩展不能够在win ...
- POJ2976:Dropping tests(01分数规划入门)
In a certain course, you take n tests. If you get ai out of bi questions correct on test i, your cum ...
- 【POJ 2407】 Relatives
[题目链接] 点击打开链接 [算法] 欧拉函数 [代码] #include <algorithm> #include <bitset> #include <cctype& ...