Advertisement
Anik_Akash

odd sum

Feb 3rd, 2021
888
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.74 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace    std;
  3.  
  4. int main()
  5. {
  6.    #ifndef ONLINE_JUDGE
  7.        freopen("input.txt","r",stdin);
  8.        freopen("out.txt","w",stdout);
  9.    #endif
  10.    int n, sum=0;
  11.    cin>>n;
  12.    if(n%2==0)
  13.    {
  14.        n = n-1;
  15.        int mid = ceil(n/2.0);
  16.        int OneSum = n+1;
  17.        int totalPair = floor(OneSum/4);
  18.        if(mid%2!=0)
  19.        {
  20.             sum = (OneSum*totalPair)+mid;
  21.        }
  22.        else  sum = (OneSum*totalPair);
  23.  
  24.    }
  25.    else
  26.    {
  27.        int mid = ceil(n/2.0);
  28.        int OneSum = n+1;
  29.        int totalPair = floor(OneSum/4);
  30.        if(mid%2!=0)
  31.        {
  32.             sum = (OneSum*totalPair)+mid;
  33.        }
  34.        else  sum = (OneSum*totalPair);
  35.    }
  36.  
  37.     cout<<sum<<endl;
  38.     return
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement