LA 4119 (differential sequence polynomial) always an integer

Source: Internet
Author: User

Test instructions

A polynomial with a shape such as (p)/d is given, where P is the integer coefficient polynomial of N and D is an integer.

Ask if the value of the polynomial is an integer for all positive integer n.

Analysis:

It can be proved by mathematical induction that if P (n) is a k-th polynomial, p (n+1)-P (n) is a K-1 quadratic polynomial.

P is a polynomial of N, p is a arithmetic progression, as long as the validation p (1) and P (2) are multiples of d.

P is a two-time polynomial of N, as long as the first item is a multiple of D, and the difference between two adjacent items is a multiple of d. The difference between the two adjacent items is a polynomial, so to verify the two items, together with the first item of the previous validation, the total validation of P (1), P (2), and P (3) three items.

In general, to verify the K-th polynomial, just verify that P (1) ... P (k+1).

The value of the polynomial can be calculated using the Qin Jiushao algorithm that the high school math textbook has talked about.

1#include <iostream>2#include <cstdio>3#include <string>4#include <cstring>5#include <cstdlib>6 using namespacestd;7 8 Const intMAXN = -+Ten;9 intA[MAXN], p;//A[i] represents the n^i corresponding coefficient, p is the highest coefficientTen  One voidParse_polynomial (strings) A { -     inti =0, Len =s.size (); -      while(I <len) the     { -         intSign =1; -         if(S[i] = ='+') i++; -         if(S[i] = ='-') {i++; sign =-1; } +         intv =0;//coefficient -          while(I < len && isdigit (S[i])) v = v *Ten+ s[i++]-'0'; +V *=Sign ; A         if(i = len) a[0] = V;//Constant Entry at         Else -         { -             if(v = =0) v =Sign ; -             intU =1;//No index -             if(S[++i] = ='^')//have index -             { inU =0; -i++; to                  while(IsDigit (s[i])) u = u *Ten+ s[i++]-'0'; +             } -A[u] =v; the             if(U > P) p =u; *         } $     }Panax Notoginseng } -  the intMoDintXintMOD) + { A     intAns =0; the      for(inti = P; I >=0; i--) +     { -Ans = (Long Long) ans * x% MOD;//Be careful not to overflow $Ans = ((Long Long) ans + a[i])%MOD; $     } -     returnans; - } the  - BOOLCheckstring&expr)Wuyi { the     intp = Expr.find ('/'); -Parse_polynomial (Expr.substr (1, P-2)); Wu     intD = Atoi (Expr.substr (p+1). C_STR ()); -      for(inti =1; I <= p+1; i++) About         if(MoD (i, D)! =0)return false; $     return true; - } -  - intMain () A { +     //freopen ("In.txt", "R", stdin); the  -     intKase =1; $     stringexpr; the      while(Cin >>expr) the     { the         if(expr[0] =='.') Break; theMemset (A,0,sizeof(a)); -p =0; inprintf"Case %d:%s\n", kase++, check (expr)?"Always an integer":"Not always an integer"); the     } the  About     return 0; the}
code June

LA 4119 (differential sequence polynomial) always an integer

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.