F-The Chosen One

F-The Chosen One

这道题目是规律题,但是好像java和python好些,然而我只会c++

代码:

java

import java.math.BigInteger;
import java.util.*;
public class Main 
{
    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("2");
            System.out.println(ans = ans.pow(n.bitLength() - 1));
        }
    }
}
View Code

python

#f = open('sample.in','r')
#g = open('sample.out','w')

f = open('in.txt','r')
g = open('out.txt','w')


test = int(f.readline())
for cas in xrange(test):
    n = int(f.readline())
    ans = 1
    while ans * 2 <= n:
        ans *= 2
    print >>g, ans

f.close()
g.close()
View Code
原文地址:https://www.cnblogs.com/kuroko-ghh/p/9528464.html