Problem
3或5的倍数
2: 偶斐波那契数
4:最大回文乘积
5 窗口移动
11:方向数组
13大整数加法 、
14最长考拉兹序列
15:网格路径
25:1000位斐波那契数
1: 3或5的倍数
在小于10的自然数中,3或5的倍数有3、5、6和9,这些数之和是23。
求小于1000的自然数中所有3或5的倍数之和。
考查倍数()% 取模运算符,整除后的余数 ,整除则为倍数
1 #include<iostream>
2 using namespace std;
6 int main(){
7 int ans=0; 8 for(int i =1;i<1000;i++){ 9 10 11 12 13 14 15 if(i%3="=0||i%5==0){" ans+="i;" } cout << ans endl; return 0; }< code></1000;i++){></iostream>
等差数列 优化重复标记
#include<iostream>
2 using namespace std;
3 首项加末项 * (sum / 首选) /2
4 int main (){
5 int sum3 =(3+999)*333/2;
6 int sum5 =(5+995)*199/2;
7 int sum15=(15+990)*66/2;
8
9 int reult = sum3 + sum5 -sum15;
10 cout << reult << endl;
11
12 return 0; 13 }</iostream>
2:偶斐波那契数
斐波那契数列中的每一项都是前两项的和。由1和2开始生成的斐波那契数列的前10项为:
1,2,3,5,8,13,21,34,55,89,…
考虑该斐波那契数列中不超过四百万的项,求其中为偶数的项之和。
1 #include<iostream>
2 using namespace std;
3
4 int main(){
5 long long temp=0;
6 int a=1;
7 int b=2;
8 while(b<4000000){ 9 10 11 12 13 14 15 16 17 if(b %2="=0" ) { temp +="b;" } b="a+b;" a="b-a;" cout << endl; return 0; }< code></4000000){></iostream>
4: 最大回文乘积
回文数就是从前往后读和从后往前读都一样的数。由两个2位数相乘得到的最大的回文数是 9009=91×99。
求由两个3位数相乘得到的最大的回文数。
最重要的反转数字 取模可以理解为lsat的数字
主方法这 公式 临时数据 =t * 10 + {x} %* 10
x/=10; 是为了last 的位子往前移
1 #include<iostream>
2 using namespace std;
3
4
5 int func(int x){
6 int raw =x ,t=0;
7 while(x){
8 t= t * 10+ x % 10;
9 x=x/10;
10 }
11 int reulte =raw==t;
12 return reulte;
13 }
14
15
16
17 int main(){
18 int temp=0;
19 for(int i=100; i<1000;i++){ 20 21 22 23 24 25 26 27 28 29 for(int j="i;j<1000;j++){" if(func(i*j)) { temp="max(temp,i*j);" } cout << endl; return 0; 30< code></1000;i++){></iostream>
5 窗口移动
1 #include<iostream>
2 using namespace std;
3
4 char str[1005];
5 int main(){
6 long long ans =0, now =1 ,count_cnt=0;
7 cin >> str;
8 for(int i=0;i<str[i];i++){ 9 10 11 12 13 14 15 16 17 18 19 if(i<13){ now windowns now*="str[i]-'0';" } else if(str[i]!="0" ) { }else{ count_cnt++; if(i>=13){
20 //则窗体向后走
21 if(str[i-13]!='0'){
22 now /=str[i-13]-'0';
23 }
24 else{
25 count_cnt--;
26 }
27 }
28 if(count_cnt ==0){ 29 ans=max(ans,now);
30 }
31 }
32 cout << ans <<endl; 33 34 return 0; }< code></endl;></str[i];i++){></iostream>
11:方向数组
Original: https://www.cnblogs.com/yijieyufu/p/16423113.html
Author: Aquiet
Title: 基础算法题
原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/581810/
转载文章受原作者版权保护。转载请注明原作者出处!