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

#include<cstdio>
#include<iostream>
#include<algorithm> using namespace std; #define N 1000001 long long sum[N*],dp[N]; int num[]; void read(int &x)
{
x=; char c=getchar();
while(!isdigit(c)) c=getchar();
while(isdigit(c)) { x=x*+c-''; c=getchar(); }
} int main()
{
int odd,even;
int x,len;
int m=N-<<;
for(int i=;i<=m;++i)
{
odd=even=;
x=i;
len=;
while(x) num[++len]=x%,x/=;
for(int j=;j<=len;++j)
{
if(num[j]&) odd+=num[j];
else even+=num[j];
}
sum[i]=abs(odd-even)+sum[i-];
}
for(int i=;i<N;++i) dp[i]=dp[i-]+(sum[i*]-sum[i])*-(sum[i*]-sum[i*-]);
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的更多相关文章

  1. CF&&CC百套计划2 CodeChef December Challenge 2017 Chef And Easy Xor Queries

    https://www.codechef.com/DEC17/problems/CHEFEXQ 题意: 位置i的数改为k 询问区间[1,i]内有多少个前缀的异或和为k 分块 sum[i][j] 表示第 ...

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

    https://www.codechef.com/DEC17/problems/CHEFHAM #include<cstdio> #include<cstring> #incl ...

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

    https://www.codechef.com/DEC17/problems/CPLAY #include<cstdio> #include<algorithm> using ...

  4. CF&&CC百套计划2 CodeChef December Challenge 2017 Chef And his Cake

    https://www.codechef.com/DEC17/problems/GIT01 #include<cstdio> #include<algorithm> using ...

  5. CF&&CC百套计划4 Codeforces Round #276 (Div. 1) A. Bits

    http://codeforces.com/contest/484/problem/A 题意: 询问[a,b]中二进制位1最多且最小的数 贪心,假设开始每一位都是1 从高位i开始枚举, 如果当前数&g ...

  6. CF&&CC百套计划4 Codeforces Round #276 (Div. 1) E. Sign on Fence

    http://codeforces.com/contest/484/problem/E 题意: 给出n个数,查询最大的在区间[l,r]内,长为w的子区间的最小值 第i棵线段树表示>=i的数 维护 ...

  7. CF&&CC百套计划1 Codeforces Round #449 C. Willem, Chtholly and Seniorious (Old Driver Tree)

    http://codeforces.com/problemset/problem/896/C 题意: 对于一个随机序列,执行以下操作: 区间赋值 区间加 区间求第k小 区间求k次幂的和 对于随机序列, ...

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

    http://codeforces.com/problemset/problem/351/D 题意: n个数的一个序列,m个操作 给出操作区间[l,r], 首先可以删除下标为等差数列且数值相等的一些数 ...

  9. CF&&CC百套计划1 Codeforces Round #449 A. Nephren gives a riddle

    http://codeforces.com/contest/896/problem/A 第i个字符串嵌套第i-1个字符串 求第n个字符串的第k个字母 dfs #include<map> # ...

随机推荐

  1. 第一次spring冲刺第3、4天

    11月14至15日 因为忙于项目的谈论与探究,以及周末的活动变动,使得博客没有时间提交上去,这里补交. 这两天,主要是应对于市场的探究做谈论,我们主要面对什么类型的客户,以及他们最需要的是什么等话题做 ...

  2. c++中的函数重载

    函数多态也称为函数重载. (1)函数重载指的是可以有多个同名的函数,因此对名称进行了重载. (2)函数重载的关键在于函数的参数列表,也称为函数特征标.如果两个函数的参数数目和参数类型相同,同时参数的排 ...

  3. Delphi 使用TAdoQuery执行存储过程的样例

    procedure TCustomerForm.FindCustomerInfo;var  strSql:string;begin //  BL_HV_FindCustomerInfo 存储过程的名称 ...

  4. mongo学习1 (转)

    关于mongodb的好处,优点之类的这里就不说了,唯一要讲的一点就是mongodb中有三元素:数据库,集合,文档,其中“集合” 就是对应关系数据库中的“表”,“文档”对应“行”. 一: 下载 上Mon ...

  5. XMind2TestCase:一个高效测试用例设计的解决方案!

    一.背景 软件测试过程中,最重要.最核心就是测试用例的设计,也是测试童鞋.测试团队日常投入最多时间的工作内容之一. 然而,传统的测试用例设计过程有很多痛点: 1.使用Excel表格进行测试用例设计,虽 ...

  6. [转帖] JVM虚拟机的历史

    Java虚拟机发展史 https://blog.csdn.net/tinyDolphin/article/details/72809018 如何查看自己的虚拟机版本?Sun Classic / Exa ...

  7. how to insert js to iframe page in order to disabled open new page/window

    how to insert js to iframe page in order to disabled open new page/window js 禁用 iframe 中的页面打开新页面 htt ...

  8. [转]跨平台开发:PhoneGap移动开发框架初探

    目前,随着Google的Android手机和苹果的iphone手机的逐渐普及,越来越多开发者加入到移动应用开发的大军当中.其中,Android应用是基于Java语言基础上进行开发的,而苹果公司的iph ...

  9. python自动化之正则

    import re phoneNumRegex=re.compile(r'\d\d\d-\d\d\d-\d\d\d\d') mo=phoneNumRegex.search('My number is ...

  10. BZOJ5312 冒险(线段树)

    记录区间and/or,修改时如果对整个区间影响都相同就打标记,否则递归.复杂度不太会证. #include<iostream> #include<cstdio> #includ ...