Rokua--p3414 sac#1-Number of combinations

Source: Internet
Author: User

P3414 sac#1-Combinatorial number topic background

The subject is provided by Sol, the world's most Konjac konjac, the most spicy chicken.

The Moon City website is the perfect Information classroom official website. Address: Http://191.101.11.174/mgzd.

Title Description

Spicy Chicken Konjac konjac Sol is a fool, he actually think the number is very cute!

Today he has a combination of numbers. Now he would like to know what Simga (c (n,i)) is, where C is the number of combinations (that is, C (n,i) means that n items have no sequential selection of i), I take from 0 to n all even numbers.

Because the answer can be large, output the remainder of the answer to 6662333.

Input/output format

Input format:

The input contains only an integer n.

Output format:

Output an integer, which is the answer.

Input and Output sample input sample #: Copy
3
Output Example # #: Replication
4
Description

For 20% of data, n <= 20;

For 50% of data, n <= 1000;

For 100% data, n <= 1 000 000 000 000 000 000 (10^18)

The permutation combination (Lucas theorem) can get 50 points,

The range of n is too large for the array to open, so you can't use the LUs theorem, we should be looking for a way

#include <cstdio>#include<cstring>#include<iostream>#include<algorithm>#defineN 1000000#defineMoD 6662333#definell Long Longusing namespacestd;intN,ans,jie[n];intRead () {intx=0, f=1;CharCh=GetChar ();  while(ch<'0'|| Ch>'9'){if(ch=='-') f=-1; ch=GetChar ();}  while(ch>='0'&&ch<='9') x=x*Ten+ch-'0', ch=GetChar (); returnx*F;} ll Qpow (ll a,ll b,ll p) {ll res=1;  while(b) {if(b&1) res=res*a%p; A=a*a%p;b>>=1; }returnRes;} ll C (ll n,ll m,ll p) {if(m>n)return 0; returnJie[n]*qpow (1ll*jie[m]*jie[n-m]%p,p-2, p)%p;} ll Lus (ll n,ll m,ll p) {if(m==0)return 1; returnLus (n/p,m/p,p) *c (n%p,m%p,p);}intMain () {n=read (); jie[0]=1;  for(intI=1; i<=n;i++) Jie[i]=1ll*jie[i-1]*i%MoD;  for(intI=0; i<=n;i+=2) ans= (Ans+lus (n,i,mod))%MoD; printf ("%d", ans); return  0;} 
50 points Lucas theorem

Play the table to find the law

#include <cstdio>#include<cstring>#include<iostream>#include<algorithm>#defineN 1000000#defineMoD 6662333#definell Long Longusing namespacestd;intN,ans,jie[n];intRead () {intx=0, f=1;CharCh=GetChar ();  while(ch<'0'|| Ch>'9'){if(ch=='-') f=-1; ch=GetChar ();}  while(ch>='0'&&ch<='9') x=x*Ten+ch-'0', ch=GetChar (); returnx*F;} ll Qpow (ll a,ll b,ll p) {ll res=1;  while(b) {if(b&1) res=res*a%p; A=a*a%p;b>>=1; }returnRes;} ll C (ll n,ll m,ll p) {if(m>n)return 0; returnJie[n]*qpow (1ll*jie[m]*jie[n-m]%p,p-2, p)%p;} ll Lus (ll n,ll m,ll p) {if(m==0)return 1; returnLus (n/p,m/p,p) *c (n%p,m%p,p);}intMain () {jie[0]=1;  for(intI=1;i< -; i++) Jie[i]=1ll*jie[i-1]*i%MoD;  for(n=1; n<= -; n++) {ans=0;  for(intI=0; i<=n;i+=2) ans= (Ans+lus (n,i,mod))%MoD; printf ("%d%d\n", N,ans); }    return  0;}
Table

We can see that ans=2^ (n-1), so we can do it with a quick power.

N Enter the time to use a long long,, (Always re ... )

#include <cstdio>#include<cstring>#include<iostream>#include<algorithm>#defineMoD 6662333#definell Long Longusing namespacestd;Long LongNintAns;ll Read () {ll x=0, f=1;CharCh=GetChar ();  while(ch<'0'|| Ch>'9'){if(ch=='-') f=-1; ch=GetChar ();}  while(ch>='0'&&ch<='9') x=x*Ten+ch-'0', ch=GetChar (); returnx*F;}intQpow (intA,ll B,intp) {    intres=1;  while(b) {if(b&1) res=1ll*res*a%p; A=1ll*a*a%p;b>>=1; }returnRes;}intMain () {n=read (); Ans=qpow (2, N-1, MoD); printf ("%d", ans); return  0;}

Rokua--p3414 sac#1-Number of combinations

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.