To is number one

Source: Internet
Author: User

Problem Descriptionone is an interesting integer. This was also an interesting problem. You is assigned with a simple task.<br>find N (3 &lt;= N &lt;=) different positive integers Ai (1 &l t;= i &lt;= N), and<br><center> </center><br><br>any possible answer'll be accepted.

Inputno input file.

Outputyour program ' s output should contain lines:
The first line contain 3 integers which is the answer for N = 3, and separated by a single blank.
The following lines is the answer for N = 4 to +, as the same format.
The sample output is the first and the lines of a possible output.

Sample Output2 3 6
2 4 6 12 The problem should be noted that the number of decomposition is less than the number plus 1 square; algorithm idea:

To decompose the denominator:

n can be decomposed into 1/n = 1/(n+1) + 1/(n+1) *n

For example starting from 2 3 6

Can not have the same so can only be decomposed from 2 to 3 6 is already contained, and then only from the beginning of 3 to change, each time from the smallest start decomposition.

Next item becomes 2 4 6 12

The next item cannot be decomposed 2 because it will come out 6 so you should choose 2 5 6 12 20

#include <iostream>
#include <cstdio>
#include <cstring>
using namespace Std;
int main ()
{int a[400],i,j,flag;
memset (A,0,sizeof (a));
A[2]=1;
A[3]=1;
A[6]=1;
printf ("2 3 6\n");
i=4;


while (i<=18)
{i++;
for (j=2;j<i*i;j++)
{
if (a[j]&&!a[j+1]&&!a[(j+1) *j])
{
a[j]=0;
A[j+1]=1;
a[(j+1) *j]=1;
Break
}
}
flag=1;
For (j=2;j< (i+1) * (i+1); j + +)
{
if (A[j])
{


if (flag)
{
printf ("%d", j);
flag=0;
}
Else
printf ("%d", j);
}
}
printf ("\ n");

}


return 0;
}

To is number one

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.