Project Euler 1-5
今天发现一个很好玩的网站: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.
#include<stdio.h> int main() { int i,ans; ans = 0; for(i = 3;i < 1000;i++) if(i % 3 == 0 || i % 5 == 0) ans += i; printf("%d\n",ans); return 0; }
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, ...
Find the sum of all the even-valued terms in the sequence which do not exceed four million.
#include<stdio.h> int main() { long long n,t,tmp,ans; t = 1; n = 1; ans = 0; while(n <= 4000000) { tmp = n; n = n + t; t = tmp; if(n % 2 == 0) ans += n; } printf("%lld\n",ans); return 0; }
Problem 3
The prime factors of 13195 are 5, 7, 13 and 29.
What is the largest prime factor of the number 600851475143 ?
#include<stdio.h> int main() { long long num = 600851475143ll; int i = 2; while (num > 1) { while(num % i == 0) num /= i; i++; } i--; printf("%d\n",i); return 0; }
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.
#include<stdio.h> int check(int n) { if(back(n) == n) return 1; return 0; } int back(int n) { int t; t = 0; while(n != 0) { t = t * 10 + n % 10; n /= 10; } return t; } int main() { int n,m,ans,max; max = -1; for(n = 100;n <= 999;n++) for(m = n;m <= 999;m++) { ans = m * n; if(check(ans) && ans > max) max = ans; } printf("%d\n",max); return 0; }
Problem 5
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 number that is evenly divisible by all of the numbers from 1 to 20?
#include<stdio.h> int main() { int ans; ans = 1 * 16 * 9 * 5 * 7 * 11 * 13 * 17 * 19; printf("%d\n",ans); return 0; }
2022年8月24日 21:44
The education board that oversees secondary and junior secondary school level education in the state of Rajasthan is called the Rajasthan Board of Secondary Education (RBSE). Released for All Streams (Science, Commerce, and Arts) is the RBSE Important Model Question Paper for 2023. on the Board's official website in PDF format. RBSE Plus One Previous Paper 2023 The RBSE New Guess Important Model Question Paper 2023 is available for download as a PDF from the official website. Important Model Question Paper 2023 is Available in PDF Format for All Streams Important Model Question Paper for the 11th Grade in Science, Commerce Subjects, RBSE 2023.
2022年9月24日 00:06
Download NCERT Sanskrit Sample Paper 2023 Class 9 gives the candidates a fair idea of new exam scheme or question pattern for all formats of the exam such as SA1, SA2, FA1, FA2, FA3, FA4 and Assignments. NCERT Sanskrit Question Paper Class 9 These NCERT STD-9 Sanskrit Sample Paper 2023 were Designed based on the newly revised syllabus and curriculum in all formats of exams conductingin Term-1 & Term-2 of the course.Download NCERT Sanskrit Sample Paper 2023 Class 9 gives the candidates a fair idea of new exam scheme or question pattern for all formats of the exam such as SA1, SA2, FA1, FA2, FA3, FA4 and Assignments.
2023年7月07日 02:53
Your code implementation seems to be correct. By using a loop and checking if each number is a multiple of 3 or 5, you successfully calculated the sum of all the multiples below 1000. digital marketing company in cochin The answer of 233168 matches the expected result. Well done on providing a working solution!