Solution of the equation

Various special sucker sentence, a wrong judgment on 40

Ideas:

There are two ideas

One,

First, find out about the border and then take the right boundary minus the left margin, very simple, it can seek according to the method of solving equations

Code (I did not break out has been 40 points, here is the nc code)

#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
typedef long long ll;
ll T,a,b,c,x,y;
ll exgcd(ll a,ll b,ll &x,ll &y)
{
    if(b==0)
    {
        x=1;y=0;
        return a;
    }
    ll d=exgcd(b,a%b,x,y);
    ll tmp=x;
    x=y;
    y=tmp-a/b*y;
    return d;
}
int main()
{
    scanf("%lld",&T);
    while(T--)
    {
        scanf("%lld%lld%lld",&a,&b,&c);
        ll d=exgcd(a,b,x,y);
        ll l=floor(1.0*c/b*(-x)),r=ceil(1.0*c/a*y);
        ll k=r-l-1;
        if(a==0&&b==0)
        {
            if(c==0)
            {
                puts("ZenMeZheMeDuo");
                continue;
            }
            else
            {
                puts("0");
                continue;
            }
        }
        if((c%d))
        {
            puts("0");
            continue;
        }
        if(1LL*a*b<0)
        {
            puts("ZenMeZheMeDuo");
            continue;
        }
        if(a==0)
        {
            if(1LL*b*c>0) puts("ZenMeZheMeDuo");
            else puts("0");
            continue;
        }
        if(b==0)
        {
            if(1LL*a*c>0) puts("ZenMeZheMeDuo");
            else puts("0");
            continue;
        }
        if(k<0)
        {
            puts("0");
            continue;
        }
        if(k>65535) puts("ZenMeZheMeDuo");
        else printf("%lld\n",k);
    }
    return 0;
}

 

two,

Seeking out and then seek out ymin ymax re / a

Very simple idea (though I think the first one is simpler)

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define A 100000
ll a,b,x,y,c,t;
ll exgcd(ll a,ll b,ll &x,ll &y)
{
    if(b==0)
    {
        x=1;y=0;
        return a;
    }
    ll c=exgcd(b,a%b,x,y);
    ll z=x;
    x=y;y=z-y*(a/b);
//    printf("x=%lld y=%lld\n",x,y);
    return c; 
}
int main()
{
//    freopen("data.in","r",stdin);
//    freopen("data.out","w",stdout);
    scanf("%lld",&t);
    while(t--)
    {
        scanf("%lld%lld%lld",&a,&b,&c);
//        printf("a=%lld b=%lld\n",a,b);
        x=0,y=0;
        if(a<0&&b<0) a=-a,b=-b,c=-c;        
        if(a==0)
        {
            if((b<=0&&c>=0)||(b>=0&&c<=0))
            {
                printf("0\n");
                continue;
            }
            else if(c%b){
                printf("0\n");
                continue;
            }
            else{printf("ZenMeZheMeDuo\n");continue;};
        }
        if(b==0)
        {
            if((a<=0&&c>=0)||(a>=0&&c<=0))
            {
                printf("0\n");
                continue;
            }
            else if(c%a){
                printf("0\n");
                continue;
            }
            else {printf("ZenMeZheMeDuo\n");continue;};
        }
        ll g=exgcd(a,b,x,y),ans=0;
        x*=c/g,y*=c/g;
//        printf("%lld %lld a=%lld b=%lld c=%lld\n",x,y,a,b,c);
        if(c%g){printf("0\n");continue;}
        if(a*b<0)
        {printf("ZenMeZheMeDuo\n");continue;}

        a/=g,b/=g,c/=g;x%=b;
        while(x<=0) x+=b;
        y=(c-a*x)/b;
        ll y2=y%a;
        while(y2<=0) y2+=a;
        ans=(y-y2)/a+1;
        if(y2>y) ans=0;
//        printf("y=%lld y2=%lld x=%lld c=%lld\n",y,y2,x,c);
        if(ans<=65535)
            printf("%lld\n",ans);
        else
            printf("ZenMeZheMeDuo\n");
    }
}

 

Topic idea was quite simple that some disgusting special sentence

Tokuban

First, $ c \ mod gcd! No solution = 0 $

Then $ a, b $ infinitely many solutions when different numbers

A infinitely many solutions when $ $ $ $ 0, $ B $ $ $ 0, $ 0 to $ $ $ C

A $ $ $ $ $ 0 to $ B $ $ $ C $ 0 $ 0 $ is not no solution

$ Ymax <ymin $ no solution

$ A == 0 $ $ b, c $ different numbers no solution

$ A == 0 $ $ b, c $ with number of infinitely many solutions

$ B == 0 $ $ a, c $ different numbers no solution

$ B == 0 $ $ a, c $ with number of infinitely many solutions

 

Guess you like

Origin www.cnblogs.com/znsbc-13/p/11227871.html