1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
program jed;

const
  limit=100;

var
  n: byte;
  k: longword;
  e: longword;
  a: array[1..2,1..10] of longword;
  c: word;

  l: byte;
  l1: byte;
  l2: word;

  i,j,j1,j2: word;

begin
  readln(n);

  for i:=1 to n do
  begin
    readln(k);
    l:=0; l1:=0;
    c := 2;
    e := trunc(sqrt(k));
    while c <= e do
    begin
      while (k mod c) = 0 do
      begin
        l:=l+1;
        k:=k div c;
      end;
      if l>0 then
      begin
        l1:=l1+1;
        a[1,l1]:=c;
        a[2,l1]:=l;
      end;
      c:=c+1;
      e := trunc(sqrt(k));
      l:=0;
    end;
    if k>1 then
    begin
      l1:=l1+1;
      a[1,l1]:=k; a[2,l1]:=1;
    end;

    l2:=0;
    for j1:=1 to l1 do
      l2:=l2+a[1,j1]*a[2,j1];
    if l2>limit then writeln('NIE')
    else
    begin
      if (l1=1) and (a[2,1]=1) then
      begin
        write('1');
        for j2:=1 to a[1,1]-1 do
          write('+1');
      end
      else
      begin
        for j:=1 to l1 do
          for j1:=1 to a[2,j] do
          begin
            if (j>1) or (j1>1) then write('*');
            write('(1');
            for j2:=1 to a[1,j]-1 do
              write('+1');
            write(')');
          end;
      end;
      writeln;
    end;
  end;
end.