[Notes 66] split count

Source: Internet
Author: User

[Reprinted please indicate the source] http://blog.csdn.net/mingyong_blog/article/details/39252363


Description

Enter a positive integer k and find all positive integers x> = Y, so that 1/k = 1/x + 1/y.

Input
Enter an integer N in the first line, which indicates that there are N groups of test data.
Enter a positive integer k in each of the next n rows.
Output

Output the corresponding K in order to find all the combinations that meet the condition 1/k = 1/x + 1/y.


Train of Thought Analysis

The key is how to process 1/k = 1/x + 1/Y. Because division is not easy to process, this formula has three Division operations, so it is converted into multiplication, convert to xy = Ky + kx.

The minimum value of X> = y is k + 1, and the value of X is obtained based on the value of Y. X = ky/(Y-k). As the value of Y increases, the value of X decreases until x <y,Break.


# Include <stdio. h> # include <stdlib. h> # include <string. h> # include <stdlib. h> int main () {INT cases; int K; int y; scanf ("% d", & cases); While (cases --) {scanf ("% d ", & K); For (y = k + 1; y ++) {int x = (k * Y)/(Y-k); If (x <Y) break; If (x * y) = K * (x + y) printf ("1/% d = 1/% d + 1/% d \ n ", k, x, y );}}}



[Notes 66] split count

Related Article

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.