Even Number Theory

题目链接

 

ps:Java水题。比赛的时候以为直接暴力。

但其实TLE.

然后打了一个表。

然而,只找到一点规律。

最后,找到了。

其实就是把数转化为二进制。

然后,遍历二进制中1.位数为n;ans+=2^n-1;

然后ans用大数;

import java.math.BigInteger;
import java.util.Arrays;
import java.util.Scanner;
 
public class bigint {
 
	public static void main(String[] args) {
        Scanner cin = new Scanner(System.in);
        int t=cin.nextInt();
        while(t>0) {
        	BigInteger n=cin.nextBigInteger();
            BigInteger ans = new BigInteger("0");
            BigInteger l = new BigInteger("1");
        	String s;
        	s=n.toString(2);
        	//System.out.println(s);
        	int len=s.length();
        	int x=0;
        	for(int i=len-1;i>=0;i--) {
        		char c=s.charAt(i);
        		//System.out.println(c);
        		if(c=='1') {
        			 BigInteger m = new BigInteger("2");
        			 m=m.pow(x);
        			 m=m.subtract(l);
        			 ans=ans.add(m);
        		}
        		x++;
        	}
        	System.out.println(ans);
        	t--;
        }
	}
}

 

C++ 并发 C++11 C++17 I encountered the concept of multithreaded code while working at my first job after I left college. We were writing a data processing application that had to populate a database with incoming data records. There was a lot of data, but each record was independent and required a reasonable amount of processing before it could be inserted into the database. To take full advantage of the power of our 10-CPU UltraSPARC, we ran the code in multiple threads, each thread processing its own set of incoming records. We wrote the code in C++, using POSIX threads, and made a fair number of mistakes—multithreading was new to all of us—but we got there in the end. It was also while working on this project that I first became aware of the C++ Standards Committee and the freshly published C++ Standard. I have had a keen interest in multithreading and concurrency ever since. Where others saw it as difficult, complex, and a source of problems, I saw it as a powerful tool that could enable your code to take advantage of the available hardware to run faster. Later on I would learn how it could be used to improve the responsiveness and performance of applications even on single-core hardware, by using multiple threads to hide the latency of time-consuming operations such as I/O. I also learned how it worked at the OS level and how Intel CPUs handled task switching. Meanwhile, my interest in C++ brought me in contact with the ACCU and then the C++ Standards panel at BSI, as well as Boost. I followed the initial development of the Boost Thread Library with interest, and when it was abandoned by the original developer, I jumped at the chance to get involved. I have been the primary developer and maintainer of the Boost Thread Library ever since.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值