201412021711-hd-Integer Solution

Source: Internet
Author: User

Integer solutionTime limit:1000/1000 MS (java/others) Memory limit:32768/32768 K (java/others) Total Submission (s): 22403 Accepted Submission (s): 7790

problem DescriptionThere are two integers, they add up equal to an integer, multiply and equal to another integer, whether they are true or false, that is, this integer does not exist, it is a bit doubt, can you answer quickly? Seems to be programmed only.
For example:
x + y = 9,x * y = 15? No such integer x and y are found
1+4=5,1*4=4, so, add up equals 5, multiply up equals 4 of two integers are 1 and 4
7+ (-8) =-1,7* (-8) =-56, so, add up equals-1, multiply equals-56 of two integers are 7 and 8
 
InputThe input data is a paired integer n,m ( -10000<n,m<10000), which represents the integer and the product, respectively, and if both are 0, the input ends.
 
OutputIt is only necessary for each N and M, the output "Yes" or "no", it is clear that there is no such integer on the line.
 
Sample Input
9 155 41-560 0
 
Sample Output
Noyesyes
Thinking of solving problemsdo not know what other people's thinking is, anyway, I was from the product, to find all of its factor pairs, and then one by one to determine the factors and is not equal to and. This time to pay attention to the existence of symbolic problems, given the product if positive, the factor can be the same or negative, if the given product is negative, then these two are a positive and negative are to be considered. Code
#include <stdio.h>int a[20050][2];int Main () {int N,m;int i,j,k,ok;while (scanf ("%d%d", &n,&m) && (n!=0| | m!=0) {k=0;if (m<0) {k=1;m=-m;} for (i=1,j=0;i*i<=m;i++) {if (m%i==0) {if (k==0) {a[j][0]=i;a[j][1]=m/i;j++;a[j][0]=-i;a[j][1]=-m/i;j++;} else{a[j][0]=-i;a[j][1]=m/i;j++;a[j][0]=i;a[j][1]=-m/i;j++;}} Note that the symbol is considered because there is a negative number}ok=0;for (i=0;i<j;i++)    if (a[i][0]+a[i][1]==n)    {    ok=1;    break;    } if (ok==1)    printf ("yes\n"); else    



201412021711-hd-Integer Solution

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.