14 条题解

  • 1
    @ 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; }

    • 1
      @ 2023-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;
      }
      
      • 0
        @ 2024-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; } ❤️

        • 0
          @ 2024-11-30 18:05:01

          非常简单,自己想 提示:for循环

          • 0
            @ 2023-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;
            }
            
            
            • -2

              #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;
              

              }

              • -2
                @ 2022-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; }

                • -2
                  @ 2022-10-1 16:32:34

                  我们知道一个数 n\ n当它被按位与11时,会变成大于等于nn,离nn最近的奇数。 所以可得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;
                  }
                  
                  • -3
                    #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;
                    

                    }

                    • -3
                      @ 2022-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);
                      }
                      
                      • -3
                        @ 2022-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;
                        }
                        
                        • -3
                          @ 2022-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;
                          

                          }

                          • @ 2022-2-25 21:58:50

                            bug好多,但终于de完了

                        • -9
                          @ 2022-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;
                          }
                          
                          • -14
                            @ 2022-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
                            上传者