Template for solving a one-dimensional linear homogeneous equations

Source: Internet
Author: User

Solution: directly add the template.

Extended Euclidean template:

 

typedef long long LL;LL ex_gcd(LL a,LL b,LL &x,LL &y){    if(b==0)    {        x=1;        y=0;        return a;    }    LL d=ex_gcd(b,a%b,x,y);    LL t=x;    x=y;    y=t-a/b*y;    return d;}

Template for solving a one-dimensional linear homogeneous equations:

 

 

LL solve (LL n) {LL a1, r1, a2, r2; LL a, B, c, r, x, y; bool ifhave = true; scanf ("% lld", & a1, & r1); for (LL I = 1; I
 
  

Question: poj 2891Strange Way to Express Integers

Code:

 

#include 
   
    #include 
    
     #include 
     
      using namespace std;typedef long long LL;LL ex_gcd(LL a,LL b,LL &x,LL &y){    if(b==0)    {        x=1;        y=0;        return a;    }    LL d=ex_gcd(b,a%b,x,y);    LL t=x;    x=y;    y=t-a/b*y;    return d;}LL solve(LL n){    LL a1,r1,a2,r2;    LL a,b,c,r,x,y;    bool ifhave=true;    scanf("%lld%lld",&a1,&r1);    for(LL i=1;i
      
       >n)    {      cout<
       
        

 

 

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.