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……2^n-1,而且提问问题的顺序是有序的,这就用到了排序。
找到的规律是:做一个表格可以清晰地看出逻辑。下图中为输入2时,边界为0-3即为横向,最大边界3是二进制1和2的和,把3分解为二进制即为纵向,表格中的结果为&结果,如果结果和纵向相等,则为√(0&结果全为X,1&1=1,为√,2&1=1,为X)。从这个表格可以看出,只要问这两个问题,不论顺序,都可以知道问题的确切值。即2的阶乘。
所以找出的逻辑关系是n的阶乘。但是考虑到给出的n的范围1e9,所以可以打表。
阶乘取模的重点!!!若阶乘的数超过这个模结果都为0!!!!
#include <iostream>
#include <string.h>
#include <cstring>
#include <algorithm>
#include <cstdio>
using namespace std;
typedef long long ll;
ll mod=1e6+3;
ll a[1000003];
int main()
{
ll ans=1;
for(ll i=1;i<1000003;i++)
{
ans=(ans*i)%mod;//阶乘
a[i]=ans;
//cout<<a[i]<<endl;
}
ll n;
while(scanf("%lld",&n)!=EOF)
{
if(n<1000003)
{
printf("%lld\n",a[n]%mod);
}
else
{
printf("0\n");//阶乘超过模,值都为0
}
}
return 0;
}