你需要找到由两个 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 最大回文数乘积的更多相关文章

  1. [LeetCode] Largest Palindrome Product 最大回文串乘积

    Find the largest palindrome made from the product of two n-digit numbers. Since the result could be ...

  2. Java实现 LeetCode 479 最大回文数乘积

    479. 最大回文数乘积 你需要找到由两个 n 位数的乘积组成的最大回文数. 由于结果会很大,你只需返回最大回文数 mod 1337得到的结果. 示例: 输入: 2 输出: 987 解释: 99 x ...

  3. Leetcode 479.最大回文数乘积

    最大回文数乘积 你需要找到由两个 n 位数的乘积组成的最大回文数. 由于结果会很大,你只需返回最大回文数 mod 1337得到的结果. 示例: 输入: 2 输出: 987 解释: 99 x 91 = ...

  4. [Swift]LeetCode479. 最大回文数乘积 | Largest Palindrome Product

    Find the largest palindrome made from the product of two n-digit numbers. Since the result could be ...

  5. 【easy】479. Largest Palindrome Product

    Find the largest palindrome made from the product of two n-digit numbers Since the result could be v ...

  6. palindrome number(回文数)

    Determine whether an integer is a palindrome. Do this without extra space. Some hints: Could negativ ...

  7. [Leetcode] Palindrome number 判断回文数

    Determine whether an integer is a palindrome. Do this without extra space. click to show spoilers. S ...

  8. 【LeetCode】9、Palindrome Number(回文数)

    题目等级:Easy 题目描述: Determine whether an integer is a palindrome. An integer is a palindrome when it rea ...

  9. 9. Palindrome Number[E]回文数

    题目 Determine whether an integer is a palindrome. An integer is a palindrome when it reads the same b ...

随机推荐

  1. NameNode备份策略以及恢复方法

    一.dits和fsimage      首先要提到两个文件edits和fsimage,下面来说说他们是做什么的. 集群中的名称节点(NameNode)会把文件系统的变化以追加保存到日志文件edits中 ...

  2. HDU3507 Print Article —— 斜率优化DP

    题目链接:https://vjudge.net/problem/HDU-3507 Print Article Time Limit: 9000/3000 MS (Java/Others)    Mem ...

  3. FileReader、 FileWriter、readLine()和newLine()、LineNumberReader(二十一)

    1.字符流FileReader * 1.字符流是什么 * 字符流是可以直接读写字符的IO流 * 字符流读取字符, 就要先读取到字节数据, 然后转为字符. 如果要写出字符, 需要把字符转为字节再写出. ...

  4. contents属性

    CALayer 有一个属性叫做contents,这个属性的类型被定义为id,意味着它可以是任何类型的对象.在这种情况下,你可以给contents属性赋任何值,你的app仍然能够编译通过.但是,在实践中 ...

  5. html5--6-60 阶段练习7-下拉菜单

    html5--6-60 阶段练习7-下拉菜单 学习要点 综合运用所学过的知识完成一个下拉菜单的小练习,加深对学过知识点的综合应用能力. <!DOCTYPE html> <html l ...

  6. poj 2185 Milking Grid(next数组求最小循环节)

    题意:求最小的循环矩形 思路:分别求出行.列的最小循环节,乘积即可. #include<iostream> #include<stdio.h> #include<stri ...

  7. [AHOI 2005] 航线规划

    [题目链接] https://www.lydsy.com/JudgeOnline/problem.php?id=1969 [算法] 首先离线 , 将删边操作转化为加边操作 不妨首先将这张图按边-双连通 ...

  8. limit的用法

    limit子句可以用于强制select语句返回指定的记录数.limit接受一个或两个数字参数,参数必须是整数常量.如果给定两个参数,第一个参数指定第一个返回记录行的偏移量,第二个参数指定返回记录行的最 ...

  9. bzoj1017 [JSOI2008]魔兽地图DotR——DP

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1017 好难想的状态啊!f[i][j][k]表示i号物品有j个向上贡献,一共花了k钱的最大力量 ...

  10. const 和指针

    c++用了那么久,觉得 const 和指针配合到一起的时候就会有点点分不出来. 如下: const Data* pData; Data const * pData Data * const pData ...