Just Skip The Problem
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 524288/524288 K (Java/Others)
Total Submission(s): 0 Accepted Submission(s): 0
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
第二场多校的签到题,题目大意是给出一个n,现在有从0到2^n-1个数,你需要找到这里面的一个数x,你可以同时问很多类似x&yi是否等于yi的问题。然后一个方法可以有很多数,不同顺序也属于不同的方法,最后方法数要对1e6+3取模。问题是最少的方法是多少种?
题目分析
拿n == 2来分析,数一共有0, 1, 2, 3,换成二进制后为00, 01, 10, 11
然后可以发现用01和10就可以找到那个x;
当n == 3时,数为000, 001, 010, 011, 100, 101, 110, 111
发现用001,010,100可以找到x。
其实对于每一位进行判断就可以找到x,所以ans = n。
但是我们还要对n个数进行排序,因为不同的顺序也属于不同的方法,所以ans = n*(n-1)*(n-2)...*2*1。
代码
#include <bits/stdc++.h>
using namespace std;
#define fr(i, r, n) for(int i = r; i < n; ++i)
const int maxn = (int)1e5 +10;
typedef long long ll;
int mod = 1e6+3;
ll init(int n)//求阶乘
{
ll ans = 1;
while(n)
{
ans = (ans * n) % mod;
n--;
}
return ans;
}
int main()
{
int n;
while(cin>>n)
{
if(n == 1)//特判
cout<<2<<endl;
else if(n >= mod)//当n >= mod时,阶乘中对mod取余后就为0了
cout<<0<<endl;
else
cout<<init(n)<<endl;
}
return 0;
}