code人心弦1101


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 ;
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值