如果发现广告等破坏行为,请尽量将条目恢复到较早的版本而不是把相应内容直接删除,谢谢合作。
URAL/1055
来自"NOCOW"
< URAL
Solution From Xcheng:
计算质因数个数的快速方法:
质因数K在1~N中出现在次数为
F(N)=sigma(n div (k^i) )
所以计算出F(N)-F(N-M)-F(M) 再统计一遍就行了。
把C(n,m)展开得C=N!/(M!·(N−M)!),再分解质因数即可.
program cao; var data,p:array[0..50000] of longint; a,b,c,d,e,f,g,h,i,j,k,l,n,m,q,total,ans:longint; function prime(x:longint):boolean; var i:longint; begin if x=2 then exit(true); for i:=2 to trunc(sqrt(x)) do if x mod i=0 then exit(false); exit(true); end; procedure work(a,b:longint); var i,j,k:longint; begin for i:=1 to total do begin if a=1 then exit; if data[i]>a then exit; while a mod data[i]=0 do begin p[i]:=p[i]+b; a:=a div data[i]; end; end; end; procedure init; begin read(n,m); if m<n-m then m:=n-m; total:=0; for i:=2 to n do if prime(i) then begin inc(total); data[total]:=i; end; end; procedure main; begin for i:=m+1 to n do work(i,1); for i:=2 to n-m do work(i,-1); end; procedure print; begin ans:=0; for i:=1 to total do if p[i]>0 then inc(ans); writeln(ans); end; begin init; main; print; end.