## 嵇爾的吐槽

#没事画轮子的嵇尔不定期的(W)碎(E)碎(B)念(B)和(L)吐(O)槽(G)

【更新到4】Project Eulor Problem 1-26,30 2016-11-08 22:28:17

## euler project:problem 1

2013-02-01 09:52:09

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.

10以内约数为3或5的数有3、5、6和9，它们的和是23。求1000以内的约数3或5的数的和。

``````int sum = 0;
int h = 1000;
for(int i = 1; i < h ; i++) {
if(i % 5 == 0) {
sum += i;
} else if(i % 3 == 0){
sum+=i;
}
}
System.out.println(sum);
``````

``````System.out.println((3+(h-1)/3*3)*((h-1)/3)/2+(5+(h-1)/5*5)*((h-1)/5)/2-(15+(h-1)/15*15)*((h-1)/15)/2);
``````

## euler project:problem 2斐波那契

2013-02-01 10:11:20

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 exceed four million, find the sum of the even-valued terms.

``````#include<stdio.h>
int fb(int i)
{
if(i == 1 || i == 2)
return 1;
else
return fb(i - 1) + fb(i - 2);
}

int main()
{
int sum = 0;
int i = 1;
for(;;i++)
{
if(fb(i) > 4000000)
break;
if(fb(i) % 2 == 0)
sum += fb(i);
}

printf("%d\n", sum);
return 0;
}
``````

## euler project:problem 3质因数

2013-02-01 10:22:19

The prime factors of 13195 are 5, 7, 13 and 29. What is the largest prime factor of the number 600851475143 ?

13195的素数约数为5、7、13和29 求600851475143的最大素数约数

``````#include <stdio.h>
#include <math.h>

int isPrime(long i)
{
long long j = 2;
if(i == 2)
{
return 1;
}

for(; j < sqrt(i); j ++)
{
if(i % j == 0)
{
return 0;
}
}

return 1;
}

int main()
{
long long i = 2;
long long largest = 0;
long long number = 600851475143;
for(; i <= number; i++)
{
if(isPrime(i) == 1)
{
if(number % i == 0)
{
largest = i;
number /= i;
printf("%lld,", i);
}
}
}
printf("\n%lld", largest);
return 0;
}
``````

## euler project:problem 4回文数

2013-02-01 10:48:18

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.

``````#include <stdio.h>

int isPalindromic(int number)
{
int i = number, result = 0;
for(; i != 0; i /= 10)
result = result * 10 + i;
return result == number;
}

int main()
{
int og1 = 1000, og2, result = 0;
for(; og1 > 99; og1--)
for(og2 = og1; og2 > 99; og2--)
if(isPalindromic(og1 * og2))
if(og1 * og2 > result)
result = og1 * og2;
printf("%d\n",result);
}
``````