Description
Pangzi recently realized thatbitwise XOR operation is just an addition without carries. Forexample, when computing (1001)_2 XOR (1101)_2, you write down:
1001
+ 1101
-------
0100
You see, everything is like anaddition, except that there are no carries.
After realizing this, Pangziinvented Super XOR. It is just an addition on decimal numberswithout carries. For example, 123 SUPERXOR 789 = 802, since 1+7=8,2+8=0, 3+9=2.
Now comes a question. Given N, find1 SUPERXOR 2 SUPERXOR 3 SUPERXOR 4 SUPERXOR ... SUPERXOR N
Input Format
The first line contains an integerT (1 <= T <= 1000), indicating thenumber of test cases.
T lines follow each containing 1integers N (1 <= N <= 10^12).
Output Format
Output T lines, each line is aninteger: the answer for the corresponding test case.
Sample Input
5
1
2
3
4
120001
Sample Output
1
3
6
0
240001
Case Limits
Time limit: 500 msec
Memory limit: 64 MB
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<set>
using namespacestd;
typedef long long LL;
int ans[15] ;
void cal(LL x){
int sum=0 ;
while(x){
ans[sum]+=(x%10) ;
ans[sum]%=10 ;
sum++ ;
x/=10 ;
}
}
bool judge(LL x){
if(x%100==99)
return0 ;
return 1 ;
}
void fun(LL left ,LL right){
memset(ans,0,sizeof(ans)) ;
LL i ;
for(i=left;i<=right;i++)
cal(i) ;
for(i=14;i>=0;i--){
if(ans[i]!=0)
break ;
}
if(i==-1)
puts("0") ;
else{
for(intj=(int)i;j>=0;j--)
printf("%d",ans[j]) ;
printf("\n") ;
}
}
int main(){
LL n , m ,t ;
cin>>t ;
while(t--){
cin>>n ;
if(n<99){
fun(1,n) ;
continue ;
}
m=n ;
while(judge(m))
m-- ;
fun(m+1,n) ;
}
return 0 ;
}