14 条题解
-
1LenGaWei (sng2023020) LV 5 @ 2023-4-26 18:37:00
#include<iostream> using namespace std; int main() { int m,n; cin>>m>>n; long long sum=0; if(m%2==0) { m++; } for(int i=m;i<=n;i+=2) { sum+=i; } cout<<sum; return 0; }
-
12023-1-26 16:59:15@
#include<iostream> using namespace std; int main() { int m,n; cin>>m>>n; long long sum=0; if(m%2==0)//求>=m的最大奇数 { m++; } for(int i=m;i<=n;i+=2)//直接从>=m的最大奇数开始+=2,sum+=i; { sum+=i; } cout<<sum; return 0; }
-
02024-12-9 22:16:44@
#include <iostream> using namespace std; int main() { int m,n,s=0; cin >> m >> n; for(int i=m;i <= n;i++) { if(i %2 == 1) { s=s+ i; } } cout << s; return 0; } ❤️
-
02024-11-30 18:05:01@
非常简单,自己想 提示:for循环
-
02023-5-8 17:15:39@
#include<iostream> #include<iomanip> using namespace std; double n , x , sum ; int main(){ cin >> n; for ( int i = 1 ; i <= n ; i++ ) { cin >> x ; sum += x ; } cout<<fixed<<setprecision(4)<<sum/n<<endl; }
-
-22023-3-22 20:17:49@
#include<bits/stdc++.h> using namespace std; int m,n,ans; int main(){
cin >> m >> n; if(m%2==0){ m++; } for(int i=m;i<=n;i += 2) { ans += i; } cout<<ans; return 0;
}
-
-22022-10-29 13:50:36@
#include<iostream> using namespace std; int main(){ double m, n; cin >> m >> n; int sum = 0; for (int i = m ; i <= n ; i++) { if (i%2 ==1) { sum +=i; } } cout << sum << endl; return 0; }
-
-22022-10-1 16:32:34@
我们知道一个数当它被按位与时,会变成大于等于,离最近的奇数。 所以可得AC Code:
#include <iostream> #include <cstdio> using namespace std; int main() { int n, m; scanf("%d %d", &n, &m); n |= 1; //变成 >=n的最近奇数 int ans = 0; while (n <= m) { ans += n; n += 2; } cout << ans; return 0; }
-
-32023-4-9 11:31:18@
#include<iostream> using namespace std; int n,m,sum; int main() { cin>>n>>m; if(n%2==0) { n+=1; } for(int i=n;i<=m;i+=1) { if(i%2==1) { sum=sum+i; } } cout<<sum; return 0;
}
-
-32022-10-31 15:16:24@
#include<iostream> #include<stdio.h> using namespace std; int main(){ int n,m,a=0; cin>>n>>m; for(int i=n;i<=m;i++){ if(i%2==1)a+=i; } printf("%d",a); }
-
-32022-9-13 17:31:13@
#include <bits/stdc++.h> using namespace std; int main(void) { int qs1, qs2; int all; cin >> qs1 >> qs2; int m = qs1 % 2; int n = qs2 % 2; if (qs1 != qs2) { if (m == 0) { qs1 = qs1 + 1; } if (n == 0) { qs2 -= 1; } if (qs1 == qs2) { all = qs1; } else { for (qs1 = qs1, qs2 = qs2; qs1 < qs2; qs1 += 2) { all = all + qs1; } all += qs1; } } else if (qs1 == qs2) { if (n == 0, m == 0) { all = 0; } if (n != 0, m != 0) { all = qs1 = qs2; } } cout << all; return 0; }
-
-32022-2-25 21:53:02@
#include <stdio.h>
#include <math.h>
int main(void)
{
int qs1 = 0, qs2 = 0; int all = 0; scanf("%d%d", &qs1, &qs2); int m = qs1 % 2; int n = qs2 % 2; if (qs1 != qs2) { if (m == 0) { qs1 = qs1 + 1; } if (n == 0) { qs2 -= 1; } if (qs1 == qs2) { all = qs1; } else { for (qs1 = qs1, qs2 = qs2; qs1 < qs2; qs1 += 2) { all = all + qs1; } all += qs1; } } else if (qs1 == qs2) { if (n == 0, m == 0) { all = 0; } if (n != 0, m != 0) { all = qs1 = qs2; } } printf("%d", all); return 0;
}
-
-92022-1-8 9:44:31@
#include <stdio.h> #include <iostream> using namespace std; int main() { double l,r; cin >> l >> r; int sum = 0; for (int i = l; i <= r ;i++ ) { if(i%2 == 1) { sum += i; } } cout <<sum <<endl; }
-
-142022-1-8 9:43:38@
#include <stdio.h> #include <iostream> using namespace std; int main() { double l,r; cin >> l >> r; int sum = 0; for(int i = l ; i <= r ; i++) { if(i%2 ==1) { sum +=i; } } cout << sum << endl; }
- 1
信息
- ID
- 928
- 时间
- 1000ms
- 内存
- 128MiB
- 难度
- 5
- 标签
- 递交数
- 1377
- 已通过
- 505
- 上传者