A simple math problem
Time Limit: 3000/1000 MS (Java/others) memory limit: 32768/32768 K (Java/Others)Total submission (s): 2780 accepted submission (s): 1649
Problem descriptionlele now is thinking about a simple function f (x ).
If x If X> = 10 f (x) = A0 * F (x-1) + A1 * F (X-2) + A2 * F (X-3) + ...... + A9 * F (X-10 );
And AI (0
Now, I will give a0 ~ A9 and two positive integers K and M, and cocould you help Lele to caculate F (k) % m.
Inputth
Hdu 1757 A Simple Math Problem (matrix fast power)A Simple Math ProblemTime Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission (s): 2512 Accepted Submission (s): 1461Problem DescriptionLele now is thinking about a simple function f (x ).If x If x> = 10 f (x) = a0 * f (x-1) + a1 * f (X-2) + a2 * f (X-3) + ...... + A9 * f (X
three bit better think, direct fast power to take surplus on it. The primary three-bit calculation.We can think of a number, for example 1589. If this number is converted, replace it with 10^x. Then x is equal to LOG10 (1589). And if we put log10 (1589) Mod 1, the result of the 1 remainder is that we only take the decimal digits of x. Imagine, if the x is divided into integers z and fractional g, then 10^x=10^ (z+g) =10^g*10^z,z is an integer, so 10^
Topic:A Simple Math problemTime limit:3000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)Total submission (s): 3522 Accepted Submission (s): 2130Problem Descriptionlele Now was thinking about a simple function f (x).If x If x >= f (x) = a0 * F (X-1) + A1 * F (x-2) + A2 * F (x-3) + ... + A9 * F (x-10);and AI (0Now, I'll give A0 ~ A9 and positive integers k and M, and could you help Lele to Caculate f (k)%m.Inputthe problem contains mut
(a, B) = c --> a * B = gcd (a, B) * C; --> A/gcd (a, B) = C/B, because a/gcd (a, B) must be an integer, so B must be a factor of C, enumerate the factors of C.
At first, the pure brute force enumeration of the factor T of C was triggered to understand that mathematics was king. The enumeration factor has been optimized when determining the prime number, that is, it only needs to be enumerated to SQRT (c ). Another condition is that a must be a factor of C. Because
b/gcd(a,b)==c/a;
#include
U
incidentally, for the Dirichlet convolution, there is a single-element E.namely: F*e=f,This unitary function has a property e[1]=1,e[k]=0,k=1,2,3 ...This will be used when the power is fast.And then on the code#include #includeusing namespaceStd;typedefLong LongLL;Const intn=1e5+5;ConstLL mod=1e9+7;intn,k; LL F[n],s[n],ans[n],tmp[n];voidsolve () { while(k) {if(k1) { for(intI=1; i0; for(intI=1; i*ii) {tmp[i*i]= (Tmp[i*i]+ans[i]*s[i])%MoD; for(intj=i+1; j*ij) Tmp[i*j]+= (Ans[
A Simple Math problemTime limit:MS Memory Limit:32768KB 64bit IO Format:%i64d %i64u SubmitStatusPracticeHDU 1757Appoint Description:System Crawler (2015-03-04)DescriptionLele now was thinking about a simple function f (x).If x If x >= f (x) = a0 * F (X-1) + A1 * F (x-2) + A2 * F (x-3) + ... + A9 * F (x-10);and AI (0Now, I'll give A0 ~ A9 and positive integers k and M, and could you help Lele to Caculate f (k)%m.InputThe problem contains mutiple test
(A.BC * 10^m)M is the integer portion of k * LG (N), and LG (A.BC) is a fractional part of K * LG (N)x = LG (A.BC) = k * LG (n)-m = k * LG (N)-(int) (k * LG (N))A.BC = POW (ten, X);ABC = A.BC * 100;So the first three digits of ABC can find#include #include#includestring.h>#include#includeusing namespaceStd;typedefLong Longll;intPow (intAintb) { intAns =1; A%= +; while(b) {if(b%2!=0) ans= (ans * a)% +; A= (A * a)% +; b/=2; } returnans;}//Fast n
[HDU 1757] A Simple Math Problem (matrix fast power)
Question:
If x If x> = 10 f (x) = a0 * f (x-1) + a1 * f (X-2) + a2 * f (X-3) + ...... + A9 * f (X-10 );And ai (0 For k and m, evaluate f (k) % m.
Solution:
F (x) = a0 * f (x-1) + a1 * f (X-2) + a2 * f (X-3) + ...... + A9 * f (X-10)
K is 10 ^ 9 orders of magnitude, so it cannot be done in recursive mode. This type of question can be done by constructing a
Topic Link: Click to open the linkTest instructions: n^m%1000000007 N (1 ,m (1 A little pit. n Too much can overflow, pow_mod (n,m,mod) =pow (n%mod,m,mod)Deduce it ...N^m%mod= (n%mod+k*mod) ^m%mod=[(n%mod) ^m +: A bunch of mods]%mod = (n%mod) ^m%modHaven't hit the code for ages .... QaqHardware to get out of the Xiang ... All day long hold the video to see how people write how to write ... Various circuit diagrams fly in the sky ..... It's like a yard farm.The fact proves that the algorithm is
Address: HDU 1757
Finally, the matrix will be constructed. In fact, it is not difficult, just blame yourself for being stupid .. =!
F (x) = A0 * F (x-1) + A1 * F (X-2) + A2 * F (X-3) + ...... + A9 * F (X-10)The constructed matrix is: (The Matrix constructed in my code is reversed up and down)| 0 1 0... 0 | f0 | F1 || 0 0 1 0... 0 | F1 | F2 || ...... 1 | * |... | = || A9 A8 ...... A0 | F9 | F10 |
Then, according to the combination Law of the matrix, we can first calculate the (K-9) Power of the c
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.