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. Android笔记-5-EditText密码和Checkbox二选一

    EditText密码:明文和密文 密文: public class MainActivity extends Activity { private EditText password = null; ...

  2. 2016011998+sw

    Coding.net原码仓库地址:https://git.coding.net/laolaf/sw.git 目录 1 需求分析 2 功能设计 3 设计实现 4 算法详解 5 测试运行 6 满意代码 1 ...

  3. APP案例分析之华为浏览器

    第一部分  对华为浏览器的调研,评测 1.对华为浏览器的第一次上手体验 我会使用华为浏览器呢,是因为我买的手机是华为nova,该浏览器也是手机里面预装的.刚开始用的时候也没太注意,感觉跟以前用的其他浏 ...

  4. HTTP&HTTPS、GET&POST

    1.HTTP&HTTPS: HTTP协议传输的数据都是未加密的,也就是明文的,因此使用HTTP协议传输隐私信息非常不安全,为了保证这些隐私数据能加密传输,于是网景公司设计了SSL(Secure ...

  5. Scrum Meeting Beta - 8

    Scrum Meeting Beta - 8 NewTeam 2017/12/7 地点:新主楼F座二楼 任务反馈 团队成员 完成任务 计划任务 安万贺 完成了博文详情的存储Issue #150Pull ...

  6. Delphi判断字符串中是否包含汉字,并返回汉字位置

    //1,函数代码{判断字符串是否包含汉字// judgeStr:要判断的字符串//posInt:第一个汉字位置}function TForm2.IsHaveChinese(judgeStr: stri ...

  7. 使用Word 进行UTF8 以及字符串编码的转换操作

    1. 使用Word文档能够实现 字符串和utf8编码的转换. 快捷键是 ALT+X 在知乎的一个里面看到一个说法: ㍾ ㍽ ㍼ ㍻ - 这四个在Unicode表里是倒序排列的,而且只预留了这四个年号, ...

  8. ZOJ2760_How Many Shortest Path

    给一个图,求从某个点到另一个点的最短路有多少条?所有的路都不共边. 首先从终点开始Spfa标记最短距离,然后建图. 建图的时候,如果满足两点之间的最短路只差为两点之间的边长,那么在网络流的模型中连接一 ...

  9. UVA 12633 Super Rooks on Chessboard(FFT)

    题意: 给你一个R*C的棋盘,棋盘上的棋子会攻击,一个棋子会覆盖它所在的行,它所在的列,和它所在的从左上到右下的对角线,那么问这个棋盘上没有被覆盖的棋盘格子数.数据范围R,C,N<=50000 ...

  10. 在HL引擎中制作自定义高清贴花

    你是不是想过要做自定义的子弹孔.喷漆或者一些自定义的痕迹呢? 如果按照HL引擎的基本FA,首先要在decals.wad里加入我们自定义的纹理,然后利用gEngfuncs.pEfxAPI->R_D ...