CF&&CC百套计划2 CodeChef December Challenge 2017 Total Diamonds

Posted 日拱一卒 功不唐捐

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了CF&&CC百套计划2 CodeChef December Challenge 2017 Total Diamonds相关的知识,希望对你有一定的参考价值。

https://www.codechef.com/DEC17/problems/VK18

 

#include<cstdio>
#include<iostream>
#include<algorithm>
 
using namespace std;
 
#define N 1000001
 
long long sum[N*2],dp[N];
 
int num[11];
 
void read(int &x)
{
    x=0; char c=getchar();
    while(!isdigit(c)) c=getchar();
    while(isdigit(c)) { x=x*10+c-0; c=getchar(); }
}
 
int main()
{
    int odd,even;
    int x,len;
    int m=N-1<<1;
    for(int i=1;i<=m;++i)    
    {
        odd=even=0;
        x=i; 
        len=0;
        while(x) num[++len]=x%10,x/=10;
        for(int j=1;j<=len;++j)
        {
            if(num[j]&1) odd+=num[j];
            else even+=num[j];
        }
        sum[i]=abs(odd-even)+sum[i-1];
    }
    for(int i=1;i<N;++i) dp[i]=dp[i-1]+(sum[i*2]-sum[i])*2-(sum[i*2]-sum[i*2-1]);
    int T,n;
    read(T);
    while(T--)
    {
        read(n);
        cout<<dp[n]<<\n;
    }
} 

 

Read problems statements in Mandarin chineseRussian andVietnamese as well.

Chef is so good at programming that he won almost all competitions. With all the prizes, Chef bought a new house. The house looks like a grid of size N (1-indexed) which consists of N × N rooms containing diamonds. For each room, the room number is equal to the sum of the row number and the column number.

The number of diamonds present in each room is equal to the absolute difference between the sum of even digits and sum of odd digits in its room number. For example, if the room number is 3216, then the number of diamonds present in that room will be |(2+6)-(3+1)| = 4.

You are given the number N. You have to print the total number of diamonds present in Chef‘s house.

Input

 

  • The first line of the input contains a single integer T denoting the number of test cases. The description of T test cases follows.
  • The only line of each test case contains a single integer N.

 

Output

For each test case, print the answer on a separate line.

Constraints

  • 1 ≤ T ≤ 105
  • 1 ≤ N ≤ 106

Subtasks

Subtask #1 (15 points):

  • 1 ≤ T ≤ 10
  • 1 ≤ N ≤ 1000

 

Subtask #2 (15 points):

  • 1 ≤ T ≤ 10
  • 1 ≤ N ≤ 106

 

Subtask #3 (70 points): original constraints

Example

Input:

3
1
2
3

Output:

2
12
36

以上是关于CF&&CC百套计划2 CodeChef December Challenge 2017 Total Diamonds的主要内容,如果未能解决你的问题,请参考以下文章

CF&&CC百套计划2 CodeChef December Challenge 2017 Penalty Shoot-out

CF&&CC百套计划2 CodeChef December Challenge 2017 Chef and Hamming Distance of arrays

CF&&CC百套计划3 Codeforces Round #204 (Div. 1) A. Jeff and Rounding

CF&&CC百套计划3 Codeforces Round #204 (Div. 1) D. Jeff and Removing Periods

完美商业计划书全攻略

[PLAN]暑期复健训练&其他东西