Факторизация

 Использовал алгоритм для некоторых чисел, потому что по диагнозу бывшей тещи "у меня плохо с устным счетом". Алгоритм простой:

;https://www.programmersforum.ru/showthread.php?t=260546
p=17*4*3*5
i=2
s$=""
While P <> 1
  A = P
  B = I
  ;Gosub 10
  While a>=B
    a=a-B
  Wend
  If A = 0
     s$=s$+Str(b);PRINT B;
     P = P / B
     If P <> 1; THEN PRINT "*";
       s$=s$+"*"
     EndIf
  Else
    I = I + 1
  EndIf
Wend
Debug s$

Но в описании подобной задачи добавлено условие: представление простых чисел должно быть с указанием степеней, а здесь получится 2*2*3*5*17,поэтому есть другой вариант:

number=1000;17*4*3*5
factor_count = 0
s$=""

    For divisor = 2 To  number
        current_factor_count = 0;
        While number % divisor = 0
            number = number/divisor;
            current_factor_count+1
            factor_count+1
        Wend
        If current_factor_count > 0
          If current_factor_count>1
            s$=s$+Str(divisor)+"^"+Str(current_factor_count)+"*"
          Else
            s$=s$+Str(divisor)+"*"
          EndIf
        EndIf
      Next divisor
      
      If Right(s$,1)="*"
        s$=Mid(s$,1,Len(s$)-1)
      EndIf
      Debug s$

Результат: 2^3*5^3


Комментарии