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*],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 chinese, Russian 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 Chef And Easy Xor Queries
https://www.codechef.com/DEC17/problems/CHEFEXQ 题意: 位置i的数改为k 询问区间[1,i]内有多少个前缀的异或和为k 分块 sum[i][j] 表示第 ...
- 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 ...
- CF&&CC百套计划2 CodeChef December Challenge 2017 Penalty Shoot-out
https://www.codechef.com/DEC17/problems/CPLAY #include<cstdio> #include<algorithm> using ...
- CF&&CC百套计划2 CodeChef December Challenge 2017 Chef And his Cake
https://www.codechef.com/DEC17/problems/GIT01 #include<cstdio> #include<algorithm> using ...
- CF&&CC百套计划4 Codeforces Round #276 (Div. 1) A. Bits
http://codeforces.com/contest/484/problem/A 题意: 询问[a,b]中二进制位1最多且最小的数 贪心,假设开始每一位都是1 从高位i开始枚举, 如果当前数&g ...
- 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的数 维护 ...
- CF&&CC百套计划1 Codeforces Round #449 C. Willem, Chtholly and Seniorious (Old Driver Tree)
http://codeforces.com/problemset/problem/896/C 题意: 对于一个随机序列,执行以下操作: 区间赋值 区间加 区间求第k小 区间求k次幂的和 对于随机序列, ...
- CF&&CC百套计划3 Codeforces Round #204 (Div. 1) D. Jeff and Removing Periods
http://codeforces.com/problemset/problem/351/D 题意: n个数的一个序列,m个操作 给出操作区间[l,r], 首先可以删除下标为等差数列且数值相等的一些数 ...
- 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> # ...
随机推荐
- object-oriented second work
work request github enter 这次作业做过,不过以前是用数组写的,当我用双向链表写这题时,刚交上去一直出错,后面我又改了改,最后一点一致凑,后面有同学告诉我在构建链表后要判断链表 ...
- Leetcode题库——24.两两交换链表中的节点
@author: ZZQ @software: PyCharm @file: swapPairs.py @time: 2018/10/20 19:49 说明:给定一个链表,两两交换其中相邻的节点,并返 ...
- systemct管理服务命令
systemctl管理服务的启动,重启,停止,重载,查看状态的命令 Systcinit命令(红帽RHEL6系统) Systemctl命令(红帽RHEL7系统) 作用 service foo star ...
- 服务 在初始化安装时发生异常:System.IO.FileNotFoundException: 未能加载文件或******
这个问题是在用installutil.exe安装服务时候碰到的 解决方法就是把installutil.exe文件直接复制到要安装的目录下 installutil.exe的所在位置 windows/mi ...
- ci钩子
钩子 - 扩展框架核心 CodeIgniter 的钩子特性提供了一种方法来修改框架的内部运作流程,而无需修改 核心文件.CodeIgniter 的运行遵循着一个特定的流程,你可以参考这个页面的 应用程 ...
- 【win10】浏览器Chrome 和edge 体验对比与使用心得
(1)Google和edge都内置了PDF阅读器,不用特意安装PDF软件了.桌面上的PDF文件可以直接用这两个浏览器打开. 然后对比来看,清晰度上美观度上,Chrome要比edge好一些.因为edge ...
- [转帖] 学习一下 apache bench 的总结简介 ( LAMP的没用过..)
PS:网站性能压力测试是性能调优过程中必不可少的一环.只有让服务器处在高压情况下才能真正体现出各种设置所暴露的问题.Apache中有个自带的,名为ab的程序,可以对Apache或其它类型的服务器进行网 ...
- toast components
toast components https://jossmac.github.io/react-toast-notifications/ https://docs.microsoft.com/en- ...
- linq 左连接实现两个集合的合并
//第一个集合为所有的数据 var specilist = new List<Me.SpecificationsInfo>(); var resultall = (from a in db ...
- Golang基础(二)
1. 条件语句 if ... else if ... else... package main import "fmt" func main() { { fmt.Printf(&q ...