comb
描述 Description
Will最近最近很磋很磋,很2很2(但是Will绝不23)……于是Will也不知道怎么就遇到了一个问题,并且Will很想让人帮他做出来。问题是这样的:在组合数C(n,0),C(n,1),……,C(n,n-1),C(n,n)中,有多少个奇数。
例如:当n=2时,C(2,0)=1,C(2,1)=2,C(2,2)=1;故总共有2个奇数。
输入格式 Input Format
输入文件有若干行,每行为一组测试数据,其中包含一个整数。
输出格式 Output Format
输出文件为。
对于每组输入,给出一个答案。
每个答案占一行,答案可能很大,你只需要输出其mod 22222223的余数即可。
样例输入 Sample Input
1
2
样例输出 Sample Output
2
2
时间限制 Time Limitation
1S
分析:做此题目时真的很囧,一开始就在纸上画来画去企图找到规律,但是费了半天劲毫无成果。最终等到别的Oier一提醒,豁然开朗……
很简单,将读入的数字转换为二进制然后统计01中1的个数t,然后求出2^t mod 22222223即可为答案,为何为这个规律,其实我也不知道,但是有这样的思路,本题就很好编了
用高精度的除法求二进制即可
贴代码:
代码
1 program p1318;
2 var a,b:array[0..301]of integer;
3 s:ansistring;
4 l,ans,tot:longint;
5
6 procedure judge;
7 var i,j,p:integer;
8 begin
9 fillchar(a,sizeof(a),0);
10 l:=length(s);
11 for i:=1 to l do
12 a[l-i+1]:=ord(s[i])-ord('0');
13 a[0]:=l;
14 p:=0;
15 ans:=0;
16 while (a[0]>0)and(a[a[0]]<>0)do
17 begin
18 for i:=a[0] downto 1 do
19 begin
20 if a[i+1]=0 then p:=0;
21 p:=p*10+a[i];
22 b[i]:=p div 2;
23 p:=p mod 2;
24 end;
25 if p=1 then inc(ans);
26 b[0]:=a[0];
27 while (b[b[0]]=0)and(b[0]>1) do dec(b[0]);
28 a:=b;
29 end;
30 tot:=1;
31 for i:=1 to ans do
32 tot:=tot*2 mod 22222223;
33 writeln(tot);
34 end;
35
36 procedure init;
37 begin
38 assign(input,'input.txt');
39 reset(input);
40 assign(output,'output.txt');
41 rewrite(output);
42 while not eof do
43 begin
44 readln(s);
45 judge;
46 end;
47 close(input);
48 close(output);
49 end;
50
51 begin
52 init;
53 end.
54

浙公网安备 33010602011771号