Interplanetary Traditions

시간 제한10초메모리 제한2048 MB

요약
행성 i에 i명이 살고 i에서 j로 사절단이 갈 때 선물 총 무게가 i*j*square가 되도록 할 때, 행성 1의 정보가 모든 행성에 전달되도록 하는 최소 희생 무게 합을 구한다.
난이도

어려움10점 중 8점

유형
정수론, 수학, 그래프, 최소 신장 트리
정답자
아직 제출이 없습니다

문제

In the universe where Svetozar lives, there are a total of nn planets, with exactly ii inhabitants living on the ii-th planet. The planets are far enough apart, so any visit of one planet's official delegation to another planet is a significant event.

Every time a delegation from planet ii plans to visit planet jj, according to tradition, each inhabitant of planet ii must send exactly jj gifts to planet jj (one gift for each inhabitant of planet jj). Each of i⋅ji \cdot j gifts, according to tradition, consists of an integer number of kilograms of magical matter, beautifully packaged and containing best wishes. All gifts must be of the same weight, as it is believed that all inhabitants on each of the two planets are equal. When the delegation arrives at the destination planet, one representative from the receiving side offers exactly one of their gifts as a sacrifice to the supreme cosmic dragon Arglwyddytywyllwch as a sign of friendship.

All local spaceships have a square shape, so the weight of one gift is always chosen so that the total weight (in kilograms) of all gifts transported from one planet to another is a perfect square of some integer (otherwise, it might be impossible to find a suitable spacecraft).

Svetozar is an outstanding scientist, and he needs to pass on confidential information to scientists from all planets without exception. Svetozar lives on planet 11, and all the scientists on this planet have already received the necessary information (since, besides Svetozar, no one lives on planet 11). The transmission of this information can occur between scientists from any two planets at the moment when a delegation from one planet arrives at another planet (it does not matter which of the two planets' scientists originally possessed the information).

Svetozar would like to pass on the information as soon as possible, and sacrifices usually take an extremely long time. He would like to arrange visits of delegations that would pass the information to all planets and at the same time have the total weight of gifts offered as sacrifices minimized. Help him while he is busy saving the universe.

입력

The only line contains one integer nn (1≤n≤5⋅10101 \leq n \leq 5 \cdot 10^{10}), denoting the number of planets.

출력

Print one integer: the minimum total weight of sacrifices to Arglwyddytywyllwch in kilograms during the visits of delegations passing on very important information.

힌트

In the third sample test, it is most optimal for the scientists of each planet to receive information directly from planet 11. The minimum possible weight of one gift when scientists from planet 11 and from planets 2,3,4,52, 3, 4, 5 meet, is respectively 2,3,1,52, 3, 1, 5, so the answer is 1111.

However, in the fourth sample test, the strategy where each planet receives information directly from the first planet gives an answer of 7878 instead of the optimal answer of 5151. In particular, it is better for inhabitants of planet 66 to obtain the information from inhabitants of planet 22 rather than planet 11, as for meeting between delegations from planets 22 and 66 exactly 1212 gifts are needed, and they can have weight equal to 33. The same meeting for planets 11 and 66 would result in a sacrifice of weight 66.

예제9

  1. 예제 1

    입력
    1
    
    예상 출력
    0
    
  2. 예제 2

    입력
    2
    
    예상 출력
    2
    
  3. 예제 3

    입력
    5
    
    예상 출력
    11
    
  4. 예제 4

    입력
    14
    
    예상 출력
    51
    
  5. 예제 5

    입력
    1234
    
    예상 출력
    117154
    
  6. 예제 6

    입력
    2670102
    
    예상 출력
    249611111111
    
  7. 예제 7

    입력
    998244353
    
    예상 출력
    24655136297102912
    
  8. 예제 8

    입력
    4294967297
    
    예상 출력
    425651411737878693
    
  9. 예제 9

    입력
    50000000000
    
    예상 출력
    51814438590328574909