CF #277 (Div. 2) A. (query rule)

Source: Internet
Author: User

CF #277 (Div. 2) A. (query rule)
A. Calculating Functiontime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard output question link: http://codeforces.com/contest/486/problem/A

For a positive integerNLet's define a functionF:

F(N)? = ?? -? 1? +? 2? -? 3? + ?..? +? (? -? 1)NN

Your task is to calculateF(N) For a given integerN.

Input

The single line contains the positive integerN(1? ≤?N? ≤? 1015 ).

Output

PrintF(N) In a single line.

Sample test (s) input
4
Output
2
Input
5
Output
-3
Note

F(4 )? = ?? -? 1? +? 2? -? 3? +? 4? =? 2

F(5 )? = ?? -? 1? +? 2? -? 3? +? 4? -? 5? = ?? -? 3



Solution:

Give you n, ask f (n ). This is a regular question. First of all, it is determined that the brute force solution cannot be solved. Because n is too large, the brute force will time out. At the same time, it cannot open such a large array for brute force.

Let's take a few simple notes and find that f (1) =-1, f (2) = 1, f (3) =-2, f (4) = 2, f (5) =-3, f (6) = 3 · this rule shows that there are two groups of numbers, if n/2 is an even number, the symbol is positive and the odd number is negative. And if n/2 is an odd number, we take an integer up, that is, n/2 + 1.

Finally, the median value is converted into long.

Complete code:

#include 
 
  #include #include 
  
   #include 
   
    #include 
    
     #include 
     
      #include 
      
       #include 
       
        #include 
        
         #include 
         
          #include 
          
           #include 
           
            #include 
            
             #include 
             
              #include 
              
               #include 
               
                #include 
                
                 #include 
                 
                  #include 
                  
                   #include 
                   
                    #include 
                    
                     #include 
                     using namespace std;#pragma comment(linker, "/STACK:102400000,102400000")typedef long long LL;typedef double DB;typedef unsigned uint;typedef unsigned long long uLL;/** Constant List .. **/ //{const int MOD = int(1e9)+7;const int INF = 0x3f3f3f3f;const LL INFF = 0x3f3f3f3f3f3f3f3fLL;const DB EPS = 1e-9;const DB OO = 1e20;const DB PI = acos(-1.0); //M_PI;int main(){ #ifdef DoubleQ freopen("in.txt","r",stdin); #endif LL n; while(~scanf("%lld",&n)) { LL c = n / 2; if(n % 2 != 0) { c += 1; printf("-"); } printf("%lld\n" , c); }}
                    
                   
                  
                 
                
               
              
             
            
           
          
         
        
       
      
     
    
   
  
 


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.