subroutine sub(num,insuu,beki) implicit none integer*8::num,beki,tmp integer*8,intent(in)::insuu beki = 1 tmp = insuu do while(MOD(num,tmp).eq.0) beki = beki + 1 tmp = tmp * insuu end do num = num*insuu/tmp beki = beki-1 return end subroutine sub subroutine bunkai(N, vinsuu, vbeki) integer*8::N,i,j,indx,fsr integer*8::vinsuu(15),vbeki(15) integer*8::num,insuu,beki integer*8,allocatable::furui(:) fsr = FLOOR(sqrt(REAL(N))) allocate(furui(fsr)) furui = 0 indx = 1 num = N do i=2, fsr if(furui(i).eq.1) cycle if(MOD(num,i).ne.0) cycle insuu = i call sub(num,insuu,beki) vinsuu(indx) = insuu vbeki (indx) = beki indx = indx + 1 if(num.eq.1) exit do j=i+i,MIN(i*i,fsr),i furui(j) = 1 end do end do if(num.ne.1) then vinsuu(indx) = num vbeki(indx) = 1 end if end subroutine bunkai program main implicit none integer*8::N,i,j integer,parameter::limit=15 integer*8::vinsuu(limit),vbeki(limit) integer*8::a,b,c,minimum data vinsuu/limit*0/,vbeki/limit*0/ data a,b,c/3*1/ read *,N call bunkai(N,vinsuu, vbeki) do i = 15,1,-1 if(vinsuu(i).eq.0) cycle do j=1,vbeki(i) minimum = MIN(a,(MIN(b,c))) if(minimum.eq.a) then a = a * vinsuu(i) else if(minimum.eq.b) then b = b * vinsuu(i) else c = c * vinsuu(i) end if end do end do print '(i0," ",i0)', a+b+c-3,N-1 end program main