Блог пользователя M_A_Noman

Автор M_A_Noman, 14 месяцев назад, По-английски

Help me to know whether there are any processes in C++ by applying which I can find out whether the decimal representation of p/q is a rational number or an irrational number.

For example 10/4 = 2.5 is a rational number where 10/3 = 3.3333333 is an irrational number

  • Проголосовать: нравится
  • -5
  • Проголосовать: не нравится

»
14 месяцев назад, # |
Rev. 2   Проголосовать: нравится +30 Проголосовать: не нравится

p/q is always a rational number by definition.

I think you meant whether decimal representation of p/q terminates or not, for that:

let d=q/gcd(p,q)

if d has only 2 and 5 as its prime factors, its decimal representation terminates, else it doesn't

  • »
    »
    14 месяцев назад, # ^ |
    Rev. 4   Проголосовать: нравится 0 Проголосовать: не нравится
    Thanks, brother I  actually want to know that.
    

    But I also want to know if d has only 2 or only 5 as its prime factor then its decimal representation terminates or the number d should contain at least one 2 and one 5 in its prime factorization

    • »
      »
      »
      14 месяцев назад, # ^ |
        Проголосовать: нравится 0 Проголосовать: не нравится

      d can have both 2 and 5 as its prime factors

      the condition is: d should not have any other prime factor except 2 and 5

      • »
        »
        »
        »
        14 месяцев назад, # ^ |
          Проголосовать: нравится 0 Проголосовать: не нравится

        where can I read more about this? Is there a name for this?

        • »
          »
          »
          »
          »
          14 месяцев назад, # ^ |
            Проголосовать: нравится 0 Проголосовать: не нравится

          umm, i know this from my mid/high school curriculum. so i dont know any reading materials.

          i dont think there is a specific name for this, you can search it like:when is the decimal representation of a rational number terminating?

      • »
        »
        »
        »
        14 месяцев назад, # ^ |
          Проголосовать: нравится 0 Проголосовать: не нравится
        Let me explain my confusion
        
        let p = 10 and q = 4
        then gcd(p,q)=2
        d = q/gcd(p,q)=2
        d has prime factor 2 so this p/q is a rational number am I right?
        
        • »
          »
          »
          »
          »
          14 месяцев назад, # ^ |
            Проголосовать: нравится +18 Проголосовать: не нравится

          as i said in the original comment, ANY p/q is a rational number.

          so, 10/3, 59/69, 69/435666828 all are rational numbers

          ......

          some rational numbers have terminating decimals, for example 10/4=2.5 (terminating decimal)

          some rational numbers have non-terminating but repeating decimals, for example 10/3=3.3333333333333.......

          • »
            »
            »
            »
            »
            »
            14 месяцев назад, # ^ |
            Rev. 2   Проголосовать: нравится 0 Проголосовать: не нравится

            My final query

            In your given example 10/4 has a terminating decimal because 4/gcd(10,4) has prime factor 2

            and 10/3 does not have any prime factor 2 or 5. That is why it does not have any terminating decimal point.

            Isn't it?

            • »
              »
              »
              »
              »
              »
              »
              14 месяцев назад, # ^ |
                Проголосовать: нравится 0 Проголосовать: не нравится

              yes,

              in 10/4, d=4/gcd(10,4)=4/2=2, d only has 2 as its prime factor. so decimal representation of 10/4 is terminating (2.5)

              while in case of 10/3, d=3/gcd(10,3)=3/1=3, which has 3 as its prime factor (a number different from 2 and 5). So, its decimal representation is repeating (3.3333...)