hdu 2092 水题还是要有套路的

来源:互联网 发布:数据vps 编辑:程序博客网 时间:2024/05/01 12:56

整数解
Time Limit: 1000msMemory Limit: 32768KB This problem will be judged on HDU. Original ID: 2092
64-bit integer IO format: %I64d Java class name: Main
Prev Submit Status Statistics Next
Type:
None

Tag it!
有二个整数,它们加起来等于某个整数,乘起来又等于另一个整数,它们到底是真还是假,也就是这种整数到底存不存在,实在有点吃不准,你能快速回答吗?看来只能通过编程。
例如:
x + y = 9,x * y = 15 ? 找不到这样的整数x和y
1+4=5,1*4=4,所以,加起来等于5,乘起来等于4的二个整数为1和4
7+(-8)=-1,7*(-8)=-56,所以,加起来等于-1,乘起来等于-56的二个整数为7和-8
Input
输入数据为成对出现的整数n,m(-10000

#include<stdio.h>int main(){    int n,m;    while(~scanf("%d %d",&n,&m)&&(n+m))    {        int f=0;        int t;        for(int i=-10001;i<=10001;i++)        {            t=n-i;            if(t*i==m)            {                f=1;                break;            }        }        if(f)        puts("Yes");        else        puts("No");    }    return 0;} 
#include<stdio.h>int main(){    int n,m;    while(~scanf("%d %d",&n,&m)&&(n+m))    {        int f=0;         int x,y,mm;        if(m>=0)            y=-1*m;        else         y=m;        mm=-1*y;        if(m==0)        f=1;        for(;y<=mm;y++)        {            if(y!=0&&!(m%y))            {                x=m/y;                if(x+y==n)                {                    f=1;                    break;                }            }        }        if(f)        puts("Yes");        else        puts("No");    }    return 0;} 
原创粉丝点击