Hdu 3304 Interesting Yang Yui Triangle

Source: Internet
Author: User

Hdu 3304 Interesting Yang Yui Triangle
Hdu 3304 Interesting Yang Yui Triangle

Question:
If P, N is given, how many Fibonacci numbers P in the nth line are not equal to 0?

Restrictions:
P <1000, N <= 10 ^ 9

Ideas:
Lucas theorem,
If:
N = a [k] * p ^ k + a [k-1] * p ^ (k-1) +... + a [1] * p + a [0]
M = B [k] * p ^ k + B [k-1] * p ^ (k-1) +... + B [1] * p + B [0]
Then:
C (n, m) = pe (I = 0 ~ K, C (a [I], B [I]) % p in which pe represents the Concatenation symbol.


Since n has been determined, a [I] (0 <= I <= k) has been determined, so we only need to find out how many types of B [I] each a [I] has, make C (a [I], B [I]) % P! = 0. The brute force attack is enough.

/* Hdu 3304 Interesting Yang Yui Triangle? Restriction: P <1000, N <= 10 ^ 9 train of thought: lucas theorem, if: n = a [k] * p ^ k + a [k-1] * p ^ (k-1) +... + a [1] * p + a [0] m = B [k] * p ^ k + B [k-1] * p ^ (k-1) +... + B [1] * p + B [0]: C (n, m) = pe (I = 0 ~ K, C (a [I], B [I]) % p in which pe represents the Concatenation symbol. Since n has been determined, a [I] (0 <= I <= k) has been determined, so we only need to find out how many types of B [I] each a [I] has, make C (a [I], B [I]) % P! = 0. The brute force attack is enough. */# Include
 
  
# Include
  
   
Using namespace std; # define LL long longconst int MOD = 10000; const int N = 105; int a [N]; int cnt = 0; int ny [N]; LL inv (LL a, LL m) {LL p = 1, q = 0, B = m, c, d; while (B> 0) {c = a/B; d = a; a = B; B = d % B; d = p; p = q; q = d-c * q;} return p <0? P + m: p;} void predo (int p) {ny [0] = 1; for (int I = 1; I
   
    

 

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.