2015 Anhui Province race B. Summation

Source: Internet
Author: User

Title Description

For positive integer n,k, we define such a function F, which satisfies the following law

Now for N and k, your task is to calculate the value of f (n,k) .

Input

The first is an integer t, which indicates that there is a T group of data next to each group of data is N and K (1<=n,k<=108)

Output

Prints the value of f (n,k), one row for each output

Sample input3 1 1 2 1 3 1Sample output-1 1-2
Find the rules.
1#include <iostream>2#include <stdio.h>3 intMain ()4 {5     using namespacestd;6     Long Longc,i,j=1, m,n,t=0, rankl=0;7     intA;8scanf"%d",&a);9      while(SCANF ("%lld%lld", &m,&n)! =EOF) {Ten         if(m==1&&n==1) {printf ("-1\n");} One         Else{ Ac=m/(2*n); -rankl=n*c*N; -          for(i=2*n*c+1; i<=m;i++) the         { -t++; -             if(t>N) -             { +J + +; -t=1; +             } A             if((j+2)%2==0) at             { -rankl=rankl+i; -             } -             Else -             { -rankl=rankl-i; in             } -         } toprintf"%lld\n", RANKL); +t=0; rankl=0; j=1; -     }} the     return 0; * } $ /**************************************************************Panax Notoginseng problem:1206 - user:2014217052 the language:c++ + Result: Correct A time:614 Ms the memory:1504 KB + ****************************************************************/

2015 Anhui Province race B. Summation

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.