ProjectEuler 004题


 1 #include<iostream>
2 using namespace std;
3
4 int main() {
5 bool isPalindromic (int num);
6 int res = 0;
7
8 for(int i = 100; i < 1000 ; i++)
9 for(int j = 100; j < 1000; j++) {
10 if( isPalindromic(i*j) && i*j > res)
11 res = i*j;
12 }
13 cout << res;
14 system("pause");
15 return 0;
16 }
17 //判断回文
18 bool isPalindromic(int num) {
19 int rev_num = 0;
20 int m = num;//商
21 while(m != 0) {
22 rev_num = rev_num * 10 + m%10;
23 m = m/10;
24 }
25 if( rev_num == num)
26 return true;
27 else
28 return false;
29 }

ProjectEuler 004题

时间: 2024-07-28 22:49:07

ProjectEuler 004题的相关文章

ProjectEuler 003题

1 //题目:The prime factors of 13195 are 5, 7, 13 and 29. 2 //What is the largest prime factor of the number 600851475143 ? 1 #include<iostream> 2 using namespace std; 3 int main() { 4 long long N = 600851475143;//int和long都为32位,long long 为64位 5 int i;

Codeforces/TopCoder/ProjectEuler 散题笔记 (持续更新)

最近做到了一些有趣的散题,于是开个Blog记录一下吧- (如果有人想做这些题的话还是不要看题解吧-) 2017-03-16 PE 202 Laserbeam 题意:有一个正三角形的镜子屋,光线从$C$点射入,求恰好反射$12017639147$次后在$C$点射出的方案数. 题解:关于反射问题容易想到对称性,不断对称翻转正三角形,可以密铺整个平面,这样一条反射$k$次的路径对应平面上经过$k$条边的路径. 然后取$CB,CA$为基,把平面画正,就能得到一个带有平行的对角线的网格图,稍微观察一下就能

ProjectEuler 005题

题目: 2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder. What is the smallest positive number that is evenly divisible by all of the numbers from 1 to 20? 此题就是求最小公倍数的,刚开始我考虑的太复杂,打算求出每个数的素数因子,然后去处一

ProjectEuler 009题

题目: A Pythagorean triplet is a set of three natural numbers, a b c, for which, a2 + b2 = c2 For example, 32 + 42 = 9 + 16 = 25 = 52. There exists exactly one Pythagorean triplet for which a + b + c = 1000.Find the product abc. 代码: 1 #include<iostream

projecteuler第二题

Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be: 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ... By considering the terms in the Fibonacci sequence whose values do not

ProjectEuler 006题

题目: The sum of the squares of the first ten natural numbers is, 12 + 22 + ... + 102 = 385 The square of the sum of the first ten natural numbers is, (1 + 2 + ... + 10)2 = 552 = 3025 Hence the difference between the sum of the squares of the first ten

Python:每日一题004

题目: 输入某年某月某日,判断这一天是这一年的第几天? 程序分析: 以3月5日为例,应该先把前两个月的加起来,然后再加上5天即本年的第几天,特殊情况,闰年且输入月份大于2时需考虑多加一天 个人的思路及代码: month_days = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30,31 ] while True: year = input("请输入年份:").strip() month = input("请输入月:").str

projecteuler之58题Spiral primes

package com.android; public class SpiralPrimes { public static void main(String args[]) { long numPrimes = 0; long numAll = 0; long oneStart = 1; for (long i = 3; i < Long.MAX_VALUE; i = i + 2) { numAll = 2*i-1; if(isPrimes(i*i)){ numPrimes++; } if(i

LeetCode刷题-004两个排序数组的中位数

给定两个大小为 m 和 n 的有序数组 nums1 和 nums2 . 请找出这两个有序数组的中位数.要求算法的时间复杂度为 O(log (m+n)) . 示例 1:nums1 = [1, 3]nums2 = [2]中位数是 2.0 示例 2:nums1 = [1, 2]nums2 = [3, 4]中位数是 (2 + 3)/2 = 2.5 1 class Solution { 2 public: 3 double findMedianSortedArrays(vector<int>&