Created
January 17, 2018 16:20
-
-
Save varshneydevansh/3614f4ca957ec6e6c51ba4df99d36cd3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Here is my code implemented in c++ | |
#include <bits/stdc++.h> | |
#define gc getchar_unlocked() | |
#define pf printf | |
using namespace std; | |
long pages[1000001], prfx[2000001]; | |
int fr() //fast input | |
{ | |
int n = 0; | |
char c = gc; | |
while (!('0' <= c && c <= '9')) { | |
c = gc; | |
} | |
while ('0' <= c && c <= '9') { | |
n = n * 10 + c - '0'; | |
c = gc; | |
} | |
return n; | |
} | |
long f(int i) | |
{ | |
int odd = 0, even =0; | |
while(i > 0){ | |
int temp = i% 10; | |
if(temp % 2 == 0) | |
{ | |
even += temp; | |
} | |
else odd += temp; | |
i = i/10; | |
} | |
return abs(odd - even); | |
} | |
int main() | |
{ | |
//ios_base::sync_with_stdio(false); | |
//cin.tie(NULL); | |
for(int i = 1; i <2000001; i++) | |
{ | |
prfx[i] = prfx[i-1]+f(i); | |
} | |
for(int i = 1; i < 1000001; i++) | |
{ | |
pages[i] = pages[i-1] + 2 * (prfx[2 * i] - prfx[i]) - f(2 *i); | |
} | |
long n, t; | |
//t = fr(); | |
scanf("%lld",&t); | |
while(t--) | |
{ | |
//n = fr(); | |
scanf("%lld",&n); | |
pf("%lld\n", pages[n]); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment