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

  1. #include<cstdio>
  2. #include<iostream>
  3. #include<algorithm>
  4.  
  5. using namespace std;
  6.  
  7. #define N 1000001
  8.  
  9. long long sum[N*],dp[N];
  10.  
  11. int num[];
  12.  
  13. void read(int &x)
  14. {
  15. x=; char c=getchar();
  16. while(!isdigit(c)) c=getchar();
  17. while(isdigit(c)) { x=x*+c-''; c=getchar(); }
  18. }
  19.  
  20. int main()
  21. {
  22. int odd,even;
  23. int x,len;
  24. int m=N-<<;
  25. for(int i=;i<=m;++i)
  26. {
  27. odd=even=;
  28. x=i;
  29. len=;
  30. while(x) num[++len]=x%,x/=;
  31. for(int j=;j<=len;++j)
  32. {
  33. if(num[j]&) odd+=num[j];
  34. else even+=num[j];
  35. }
  36. sum[i]=abs(odd-even)+sum[i-];
  37. }
  38. for(int i=;i<N;++i) dp[i]=dp[i-]+(sum[i*]-sum[i])*-(sum[i*]-sum[i*-]);
  39. int T,n;
  40. read(T);
  41. while(T--)
  42. {
  43. read(n);
  44. cout<<dp[n]<<'\n';
  45. }
  46. }

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

  1. Input:
  2.  
  3. 3
  4. 1
  5. 2
  6. 3
  7.  
  8. Output:
  9.  
  10. 2
  11. 12
  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. Reaction to 构造之法 of Software Engineering From The First Chapter toThe Fifth Chapter(补充版)

    几个星期前,我阅读过一篇文章,一位老师教导自己的学生要积极地去阅读文学文献,其中,我很欣赏他的一句话:“Just think of liturature as if you're reading a ...

  2. asp.net文件上传接收不到文件 Request.files["']等于null

    这个时候你应该检查下你的form表单里面是否配置了这个: enctype ="multipart/form-data"  新手容易出错哦. <form id="fo ...

  3. OSI协议和TCP/IP协议笔记

    1.OSI协议: 第7层应用层:OSI中的最高层.是用户与网络的接口.该层通过应用程序来完成网络用户的应用需求,如文件传输.收发电子邮件等.在此常见的协议有:HTTP,HTTPS,FTP,TELNET ...

  4. 电梯调度系统(界面由C图形库编绘)

    电梯调度系统编程 1.编程题目 电梯调度. 2.结对编程组员 黄冠译,刘畅. 3.编程语言 C语言图形库. 4.题目要求: 5.代码运行及结果调试: ① 运行界面为C++图形库支持,开始运行的初始界面 ...

  5. PAT 1068 万绿丛中一点红

    https://pintia.cn/problem-sets/994805260223102976/problems/994805265579229184 对于计算机而言,颜色不过是像素点对应的一个 ...

  6. 关于JEE web项目 Servlet中 “/” 的解释 ;

    1.关于"/" 可以代表web应用的根目录,也可以代表站点的根目录: 1>如果交给浏览器解析,则代表web站点的根目录,如果交给web服务器解析则代表项目的根目录: 2> ...

  7. vue使用axios发送数据请求

    本文章是基于vue-cli脚手架下开发 1.安装 npm install axios --s npm install vue-axios --s 2.使用.在index.js中(渲染App组件的那个j ...

  8. Linux环境下安装配置Mysql

    首先我们的使用的是linux的 centOS6 版本 安装mysql: 1.查看有没有安装包 yum list mysql* 2.进行安装mysql:一般我们在服务器端安装的都是服务端( mysql- ...

  9. BZOJ3243 NOI2013向量内积(随机化)

    考虑奇技淫巧. 首先是k=2.对向量维护一个前缀和,每次将当前向量与前缀和点乘.如果点乘结果不等于i-1&1,说明当前向量至少和之前的某个向量的数量积是2的倍数,暴力找就可以了.当然等于i-1 ...

  10. 【刷题】BZOJ 2243 [SDOI2011]染色

    Description 给定一棵有n个节点的无根树和m个操作,操作有2类: 1.将节点a到节点b路径上所有点都染成颜色c: 2.询问节点a到节点b路径上的颜色段数量(连续相同颜色被认为是同一段), 如 ...