Hdu 5615 Jam ' s math problem (cross multiply judgment)

Source: Internet
Author: User

D.

Jam has a math problem to ask you, he just learned to factorization for example,X^2+6x+5= (x+1) (x+5)It's like a shape.Ax^2+bx+c=pqx^2+ (QK+MP) x+km= (px+k) (qx+m)< Span class= "Mrel" >< Span class= "Mord mathit" >  But he's stupid, he only does 
                                                                                                     
                                                                                                      p,q,m,k p , q,m,k as a positive integer please help him and ask if you can break it down           
                                                                                                      

Test instructions is asking a one-dollar two-time equation can the decomposition of cross-multiplication?

S.

The official problem: The first question is relatively simple, can be said to be a simple simulation problem, we considera,b,c10^9 < Span class= "Mord" > ?? , so we decided to reduce the complexity of the time,

for each number, because it is positive, so we can handle it a lot easier, for example 32=2*16< Span class= "base textstyle uncramped" > 216

In this way, time becomesO(√? a??? Yes? b??? ), easy to solve the problem

Is the enumeration, I think so ...

At that time the feeling may time out, also thought the composite decomposition .... I didn't do it at the end. It's a lot of thought.

PS: If you know the following, then this problem is much easier ...

For a polynomial like ax²+bx+c, the Δ=B²-4AC can be used to determine whether it can use the cross decomposition method to decompose the form. When Δ is a full-squared number, the polynomial can be multiplied by a cross-range of integers.

C. Enumeration

#include <iostream>#include<stdio.h>#include<math.h>using namespacestd;inta,b,c;intp[20000],cnt1;//Pintk[20000],cnt2;//kBOOLf () {Cnt1=cnt2=0; intSqrt1= (int) sqrt (a);  for(intI=1; i<=sqrt1;++i) {        if(a%i==0) {P[cnt1++]=i; P[cnt1++]=a/i; }    }    intSqrt2= (int) sqrt (c);  for(intI=1; i<=sqrt2;++i) {        if(c%i==0) {K[cnt2++]=i; K[cnt2++]=c/i; }    }    intq,m;  for(intI=0; i<cnt1;++i) {         for(intj=0; j<cnt2;++j) {Q=a/P[i]; M=c/K[j]; if(q*k[j]+m*p[i]==b) {                return true; }        }    }    return false;}intMain () {intT; scanf ("%d",&u);  while(t--) {scanf ("%d%d%d",&a,&b,&c); if(f ()) {printf ("yes\n"); }        Else{printf ("no\n"); }    }    return 0;}
View Code

C2. When δ is a full-squared number, the polynomial can be multiplied by a cross-range of integers.

#include <iostream>#include<stdio.h>#include<math.h>using namespacestd;intMain () {intT;    __int64 A,b,c;    __int64 k,m; scanf ("%d",&T);  while(t--) {scanf ("%i64d%i64d%i64d",&a,&b,&c); M=b*b-4*a*C; K=(__int64) sqrt (m); if(k*k==L) {printf ("yes\n"); }        Else{printf ("no\n"); }    }    return 0;}
View Code

Hdu 5615 Jam ' s math problem (cross multiply judgment)

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.