Just Skip The Problem
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Others)
Problem Description
Y_UME has just found a number x in his right pocket. The number is a non-negative integer ranging from 0 to 2n−1 inclusively. You want to know the exact value of this number. Y_UME has super power, and he can answer several questions at the same time. You can ask him as many questions as you want. But you must ask all questions simultaneously. In the i-th question, you give him an integer yi ranging from 0 to 2n−1 inclusively, and he will answer you if x&yi equals to yi or not. Note that each question you ask has a index number. Namely, the questions are ordered in certain aspect. Note that Y_UME answer all questions at the same time, which implies that you could not make any decision on the remaining questions you could ask according to some results of some of the questions.
You want to get the exact value of x and then minimize the number of questions you will ask. How many different methods may you use with only minimum number of questions to get the exact value of x? You should output the number of methods modulo 106+3.
Two methods differ if and only if they have different number of questions or there exsits some i satisfying that the i-th question of the first method is not equal to the i-th of the second one.
Input
There are multiple test cases.
Each case starts with a line containing one positive integer n(n≤109).
Output
For each test case, output one line containing an integer denoting the answer.
Sample Input
2
Sample Output
2
思路:
题意的意思是假如再0-2n - 1中有多少个数可以知道x的确切值,所以从二进制的角度看就是要知道每个位上是否有1,比如3那就是11所以只要知道两个位是1其余位为0,就知道是否是3,而题目中也有一个判断,就是x & yi = yi所以假如包含了1.这个就会相等,所以就是全部位只有一个1的(比如1,2,4,8,16)有几个,然后全排列就行了。
#include <iostream>
#include <cstdio>
using namespace std;
const int mod = 1e6 + 3;
typedef long long ll;
int main() {
ll n;
while (scanf("%lld",&n) != EOF) {
ll sum = 1;
if(n >= mod) printf("0\n");
else {
for(ll i = 1; i <= n; i++) {
sum = (sum * i) % mod;
}
printf("%lld\n", sum);
}
}
return 0;
}