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

最新文章

  1. 女生的最爱,装饰品。WPF也有,Adorner。(上海晒衣服理念)
  2. 跨域请求ajax jsonp的使用解惑
  3. CSS3关于transition过渡
  4. 【缓存】.net中Cache管理操作
  5. 折腾ghost。。。
  6. 注意!ASP.NET MVC 3 的一个 OutputCache 问题
  7. 使用Doxygen工具生成Cocos2D-x 2.1.0文档
  8. Python之路【第二十二篇】:Django之Model操作
  9. ajax大数据排队导出+进度条
  10. 内存管理pbuf.h头文件源码解析——LwIP学习
  11. ls命令 ls -trl
  12. ComboBox值排序
  13. XtraBackup应用说明(支持TokuDB)
  14. java 学习(二)
  15. Java_Scanner和System类
  16. 校园服务nabcd需求分析
  17. (原创)Spice 网表范例
  18. 由consequence忽然发现英语也挺有意思
  19. web页面简单布局的修改,测试中的应用
  20. android 读取EXcel 文件 读取文件内存卡的权限

热门文章

  1. HDU 4123 Bob’s Race 树形dp+单调队列
  2. JVM面试问题
  3. MongoDB安装笔记
  4. beta发布简评
  5. linux ls文件颜色和底色设置
  6. 第217天:深入理解Angular双向数据绑定的原理
  7. 【Python】使用python操作mysql数据库
  8. POJ3041_Asteroids
  9. JAVA LOG4J使用方法
  10. Sort HDU - 5884(优先队列+二分)