Home > Back-end >  Kill people don't want 3 n 1 suspect
Kill people don't want 3 n 1 suspect

Time:09-26

For any positive integer n, if it is even, then cut it half; If it is odd, then put (3 n + 1) cut in half, so has been cut down repeatedly, finally must be in a particular step by n=1, given any positive integer n is not more than 1000, simply count, how many steps (cut) for n=1?


I want to ask is why loop condition is not the inside of the box? Thank you for passing bosses give directions,

CodePudding user response:

n<=1000 & amp; & N>=0 is conditions, and no limit cycle, cycle conditions as long as it is!=keep
You the conditions to join the cause problems, such as cannot be divided exactly by 2, 999 to 999 x3 + 1 this & gt; 1000, withdrew from the cycle,

CodePudding user response:

The
reference 1/f, 5250 response:
n<=1000 & amp; & N>=0 is conditions, and no limit cycle, cycle conditions as long as it is!=keep
You the conditions to join the cause problems, such as cannot be divided exactly by 2, 999 to 999 x3 + 1 this & gt; 1000, withdrew from the cycle,

Oh, that the conditions do not need to write, is the time to run time input yourself understand this limitation, to avoid illegal input values?

CodePudding user response:

The
reference 4 floor LINUX/response:
Quote: reference 1/f, 5250 response:
n<=1000 & amp; & N>=0 is conditions, and no limit cycle, cycle conditions as long as it is!=keep
You the conditions to join the cause problems, such as cannot be divided exactly by 2, 999 to 999 x3 + 1 this & gt; 1000, withdrew from the cycle,

Oh, that the conditions do not need to write, is the time to run time input yourself understand this limitation, to avoid illegal input values?




Well, if you really want to limit the input, you can join judgment
If (n<=0 | | n> 1000)
Printf (" input range over ");

CodePudding user response:

Uh-huh, I see, thank you for your big help,

CodePudding user response:

5250 references 5 floor response:
Quote: LINUX/reference 4 floor response:

The
Quote: reference 1/f, 5250 response:
n<=1000 & amp; & N>=0 is conditions, and no limit cycle, cycle conditions as long as it is!=keep
You the conditions to join the cause problems, such as cannot be divided exactly by 2, 999 to 999 x3 + 1 this & gt; 1000, withdrew from the cycle,

Oh, that the conditions do not need to write, is the time to run time input yourself understand this limitation, to avoid illegal input values?




Well, if you really want to limit the input, you can join judgment
If (n<=0 | | n> 1000)
Printf (" input range over ");

Uh-huh, I see, thank you for your big help,
  • Related