HDU 3304 Interesting Yang Yui Triangle Lucas theorem

Source: Internet
Author: User
Tags cas

Enter P N to find out how many of the n+1 lines of the Yang Hui triangle cannot be divisible by P

Lucas theorem: A, B are non-negative integers, p is prime. AB is written in P-system: a=a[n]a[n-1]...a[0],b=b[n]b[n-1]...b[0].
The combined number C (A, B) and C (A[n],b[n]) *c (a[n-1],b[n-1]) *...*c (a[0],b[0]) mod p congruence

That is: Lucas (n,m,p) =c (n%p,m%p) *lucas (n/p,m/p,p), when there is i,b[i]>a[i], the MoD value is 0, so it must be divisible; when for all I,b[i]<=a[i], a[i]!%p!=0, So it must not be divisible.

#include <cstdio>
#include <cmath>
#include <cstring>
using namespace std;

int main ()
{
    int p, n;
    int cas = 1;
    while (scanf ("%d%d", &p, &n)! = EOF)
    {
        if (p ==0 && n ==0) break
            ;
        int sum = 1;
        while (n)
        {
            sum *= n%p+1;
            n/= p;
        }
        printf ("Case%d:%04d\n", cas++, sum%10000);
    }
}


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.