#include<bits/stdc++.h>usingnamespace std;intmain(){int sum =0;
sum +=(3+999)*(999/3)/2;
sum +=(5+995)*(995/5)/2;
sum -=(15+990)*(990/15)/2;
cout << sum;return0;}
T2 偶斐波那契数
#include<bits/stdc++.h>usingnamespace std;intmain(){int a =1, b =2, c;int sum =2;while(true){
c = a + b;if(c >4000000)break;if(c %2==0) sum += c;
a = b;
b = c;}
cout << sum;return0;}
T3 最大质因数
#include<bits/stdc++.h>usingnamespace std;intmain(){longlong n =600851475143, ans;for(int i =2; i <= n / i; i ++){while(n % i ==0){
ans = i;//满足条件的 i 一定是个质数
n /= i;}}if(n >1) ans = n;
cout << ans;return0;}/*
这条语句是必须的。
if (n > 1) ans = n;
举例n = 14,则循环是从2到sqrt(14),也就是从2到3
循环结束时n = 7,
对于某些数字,比如8, 循环结束时n = 1
*/
T4 最大回文乘积
#include<bits/stdc++.h>usingnamespace std;intmain(){for(int i =999; i >=100; i --){//构造一个6位回文数 int x = i *1000+ i %10*100+ i /10%10*10+ i /100;for(int j =999; j >=100; j --){if(x % j ==0){int y = x / j;if(y >=100&& y <=999){
cout << x;return0;}}}}return0;}
T5 最小公倍数
#include<bits/stdc++.h>#defineLLlonglongusingnamespace std;intgcd(int x,int y){return y ?gcd(y, x % y): x;}intmain(){int ans =1;for(int i =2; i <=20; i ++){int t =gcd(ans, i);
ans = ans / t * i;}
cout << ans;return0;}
T6 和的平方与平方的和之差
#include<bits/stdc++.h>usingnamespace std;intmain(){int s1 =0, s2 =0;for(int i =1; i <=100; i ++){
s1 += i;
s2 += i * i;}
cout << s1 * s1 - s2;return0;}
T7 第10001个质数
#include<bits/stdc++.h>usingnamespace std;constint N =2e5+10;int a[N];int p[N], n;intmain(){for(int i =2; i <=200000; i ++){if(!a[i]){
p[++ n]= i;for(int j =2; i * j <=200000; j ++){
a[i * j]=1;}}}
cout << p[10001];return0;}/*
当n很大时,正整数 1~n 范围内的质数个数,约等于 n / ln(n)
*/
T8 连续数字最大乘积
#include<bits/stdc++.h>usingnamespace std;int a[1000];intmain(){
string s;
cin >> s;for(int i =0; i <1000; i ++) a[i]= s[i]-'0';longlong maxx =0;for(int i =12; i <1000; i ++){longlong res =1;for(int j = i -12; j <= i; j ++) res *= a[j];
maxx =max(maxx, res);}
cout << maxx;return0;}
T9 特殊毕达哥拉斯三元组
#include<bits/stdc++.h>usingnamespace std;intmain(){for(int i =1; i <=1000; i ++){for(int j = i +1; j <=1000; j ++){int k =1000- i - j;if(i * i + j * j == k * k){
cout << i * j * k;return0;}}}return0;}
T10 质数求和
#include<bits/stdc++.h>usingnamespace std;constint N =2e6+10;bool a[N];intmain(){longlong s =0;for(int i =2; i <2000000; i ++){if(!a[i]){
s += i;for(int j = i; j <2000000; j += i){
a[j]=true;}}}
cout << s;return0;}