Problem 9 Special Pythagorean triplet

Problem 9: Special Pythagorean triplet

https://projecteuler.net/problem=9

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 pro[……]

>> 阅读全文…

Problem 8 Largest product in a series

Problem 8: Largest product in a series

https://projecteuler.net/problem=8

The four adjacent digits in the 1000-digit number that have the greatest product are 9 × 9 × 8 × 9 = 5832.

73167176531330624919225119674426574742355349194934
96983520312774506326239578318016984801869478851843
858615607891129[……]

>> 阅读全文…

Problem 7 10001st prime

Problem 7: 10001st prime

https://projecteuler.net/problem=7

By listing the first six prime numbers: 2, 3, 5, 7, 11, and 13, we can see that the 6th prime is 13.

What is the 10 001st prime number?

分析

第10001个质数.

方法1 递增遍历寻找质数

Problem 3 Largest Prime Factor 题目中,我们有提到过一个质数分布的规律:

关于质数分布的规律:大于等于5的质数一定[……]

>> 阅读全文…

Problem 6 Sum square difference

Problem 6: Sum square difference

https://projecteuler.net/problem=6

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[……]

>> 阅读全文…

Problem 5 Smallest multiple

Problem 5: Smallest multiple

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?

分析

能整除1~20的最小正整数,即 1~20的最小公倍数

能被11~20 整除的数,肯定能被1~10 整除。所以问题可以转换为求能[……]

>> 阅读全文…

Problem 4 Largest palindrome product

Problem 4: Largest palindrome product

https://projecteuler.net/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.

分析

两个3位数乘积能得到的最大回文[……]

>> 阅读全文…

Problem 3 Largest prime factor

Problem 3: Largest prime factor

https://projecteuler.net/problem=3

The prime factors of 13195 are 5, 7, 13 and 29.

What is the largest prime factor of the number 600851475143 ?

分析

最大质因数问题。求600851475143的最大质因数。

方法1 暴力求解

从 N=600851475143, N=a*i,i从1开始,计算a,判断a是否为质数,是则返回结束

CPP

C\C++ 中int类型(包括long int类型)[……]

>> 阅读全文…

Problem 2 Even Fibonacci numbers

Problem 2: Even Fibonacci numbers

https://projecteuler.net/problem=2

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 sequenc[……]

>> 阅读全文…

Problem 1 Multiples of 3 and 5

Problem 1: Multiples of 3 and 5

https://projecteuler.net/problem=1

If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23.

Find the sum of all the multiples of 3 or 5 below 1000.

分析

欧拉计划第一题,入门,相当于其它OJ系统的a+b题目。题目虽简单,却不能就题论题,提[……]

>> 阅读全文…

C++实现通过基类指针调用子类的私有函数(易错点)

请看下面的例子,它成功调用了类的私有成员函数。

[cpp]//鸟,可以飞
class Bird {
public:
virtual void fly(){cout<<"Bird fly"<<endl;};
};

//鸵鸟,是鸟,但不可飞
class Ostrich: public Bird
{
private:
void fly(){cout<<"Ostrich cannot fly"<<endl;};
};

int main(int argc, char* argv[……]

>> 阅读全文…

Windows下sqlite3的编译使用总结

方法一 源码加入项目,直接使用

1. 下载 sqlite-amalgamation-3080401.zip 源码包

这是一个源代码的合并包,sqlite3源代码的所有文件都被合并成了一个sqlite3.c文件

2. 解压源码包

解压目录包括四个文件

  1. (1) sqlite3.c      : 源代码合并的文件
  2. (2) sqlite3.h      : 头文件
  3. (3) sqlite3ext.h : 支持动态扩展功能时替换sqlite3.h使用。动态扩展的意思是不需要重新编译sqlite就可以添加新的函数和规则。(动态扩展是试验性质的功能,后期可能转为正式也可能剔[……]

    >> 阅读全文…

C++中public,protected,private访问(转)

注:本想自己写一点笔记,但是发现了下面这篇文章已经总结的很好,就转过来了珍藏吧。

转自: 网易博客 – 好记性不如烂笔头—Leo – C++中public,protected,private访问

—————————————————————————————————————–

当private,public,protected单纯的作为一个类中的成员权限设置时:

XAMPP中Apache服务启动失败的解决方案

1. 可能是80端口被其它程序占用

解决方法:打开安装目录 \xampp\apache\conf 文件夹下的httpd.conf 文件,修改所有的80为8081.

以后在浏览器中使用localhost:8081

2. 可能是443端口被其它程序占用 

解决方法:打开安装目录 \xampp\apache\conf\extra 文件夹下httpd-ssl.conf 文件,修改所有的443为其它值,如4433.

3. 可能是配置文件有错

解决方法:命令行进入\xampp\apache\bin 目录,执行

[shell]httpd – t[/shell]

检查配置文件那里出错了。根据报错信息,找到httpd.conf[……]

>> 阅读全文…

绕中心点顺序旋转的n*n数组

问题

给定一个n,n为奇数,求一个n*n的二维数组,1 位于数组的中心,其它数绕中心点依次旋转并递增,如n=5时,数组如下:

21 22 23 24 25
20  7  8  9 10
19  6  1  2 11
18  5  4  3 12
17 16 15 14 13

思路

示意图.jpg

中心点的坐标为(row,col)=(n/2,n/2),(数组下标均从0开始)。

第1圈:边长side_len=2*1+1=3,从 2开始,先往下走side_len-1 = 2 步,再往左走2步,再往上走2步,最后往右走2步。

第2圈:边长side_len=2*2+1=5,从 10开[……]

>> 阅读全文…

沿45°递增的n*n数组

问题

给定一个n,求一个n*n的二维数组,该数组的值沿45°方向的斜线依次递增。如n=4时,数组为

  1   2   4   7
  3   5   8  11
  6   9  12  14
 10  13  15  16

思路

将数组分成上三角(包括对角线)和下对角两个部分分别计算。

对于上三角,共有n条斜线,每条斜线上的数字个数分别为cnt = 1,2,3,…,n。每条斜线的起点是(row,col) =(0,i),其中i=0 ,1,…, n-1。数组下标从0开始。每条斜线的下一个位置是当前行数row+1,当前列数col-1.

对于下三角,共有n-1条斜线,每条[……]

>> 阅读全文…