Statistics

Problem Statement for "Procrastination"

Problem Statement

You are working in the Huge Software Company. The company is so huge that it has an infinite number of employees. Employee number 1 is reserved for the Big Boss and Legendary Founder of the company, Mr. Z. Ordinary employees are numbered using positive integers, starting from 2.

At the beginning of the day each employee is assigned a task they should accomplish: for each x from 2 to infinity, employee number x is assigned task number x. During the day some pairs of employees will swap the tasks they were assigned. The swapping follows a precise schedule that is described below.

The working day in the Huge Software Company has infinitely many hours. The hours are numbered using positive integers, starting from 1. During hour 1 there are no swaps at all. During each of the following hours there are infinitely many swaps. These look as follows:

  • During hour 2 we have the following swaps: workers 4 and 5 swap their tasks, workers 6 and 7 swap their tasks, workers 8 and 9 swap their tasks, and so on.
  • During hour 3 we have the following swaps: workers 6 and 7 swap their tasks, workers 9 and 10 swap their tasks, workers 12 and 13 swap their tasks, and so on.
  • ...
  • Formally, for each h greater than or equal to 2, during hour h we look at all workers that have numbers divisible by h and strictly greater than h. Each of these workers will swap the task they currently have with the worker with a number one larger than their own.

It can be shown that for each employee there is a finite number of hours after which the employee will never swap their current task with anyone. It can also be shown that for each task there is a finite number of hours after which the task will remain with the current employee forever.

You are given a long n. Compute and return the number of employee who will have the task number n at the end of the day.

Definition

Class:
Procrastination
Method:
findFinalAssignee
Parameters:
long
Returns:
long
Method signature:
long findFinalAssignee(long n)
(be sure your method is public)

Constraints

  • n will be between 2 and 10^10, inclusive.

Examples

  1. 3

    Returns: 3

    Employee 3 is never involved in any swaps: neither with employee 2, nor with employee 4.

  2. 8

    Returns: 11

    Task 8 starts assigned to employee 8. During hour 2 this employee swaps it for another task with employee 9. During hour 3 employee 9 gives this task to employee 10. Finally, during hour 5 employee 10 gives this task to employee 11 where it will stay forever.

  3. 20

    Returns: 20

    Task 20 goes from employee 20 to employee 21 (during hour 2), then to employee 22 (during hour 3), then back to employee 21 (during hour 7), and finally back to employee 20 (during hour 10). This is where it then remains forever.

  4. 196248

    Returns: 196259

  5. 5587021440

    Returns: 5587021440

  6. 10000000000

    Returns: 10000000003

  7. 999999542

    Returns: 999999542

  8. 999999999

    Returns: 999999999

  9. 9998242

    Returns: 9998244

  10. 9998244

    Returns: 9998242

  11. 9991925

    Returns: 9991918

  12. 9991918

    Returns: 9991925

  13. 9928807

    Returns: 9928798

  14. 99999999

    Returns: 100000001

  15. 100000001

    Returns: 99999999

  16. 42424242

    Returns: 42424242

  17. 99979999

    Returns: 99980000

  18. 99980000

    Returns: 99979999

  19. 99960004

    Returns: 99960005

  20. 299982400

    Returns: 299982398

  21. 299982398

    Returns: 299982400

  22. 2500000001

    Returns: 2499999998

  23. 2499999998

    Returns: 2500000001

  24. 2499997503

    Returns: 2499997503

  25. 9997400374

    Returns: 9997400374

  26. 9997400171

    Returns: 9997400168

  27. 9997400168

    Returns: 9997400171

  28. 9997399441

    Returns: 9997399441

  29. 6983776805

    Returns: 6983776805

  30. 9999799998

    Returns: 9999800001

  31. 2

    Returns: 2

  32. 4

    Returns: 5

  33. 5

    Returns: 4

  34. 6

    Returns: 6

  35. 7

    Returns: 7

  36. 17

    Returns: 17

  37. 9

    Returns: 9

  38. 10

    Returns: 10

  39. 11

    Returns: 8

  40. 12

    Returns: 12

  41. 13

    Returns: 13

  42. 14

    Returns: 16

  43. 15

    Returns: 15

  44. 16

    Returns: 14

  45. 9999999999

    Returns: 9999999999

  46. 3141592653

    Returns: 3141592653

  47. 4302407380

    Returns: 4302407380

  48. 4561509945

    Returns: 4561509945

  49. 3837921797

    Returns: 3837921797

  50. 95769099

    Returns: 95769099

  51. 2000000015

    Returns: 2000000015

  52. 1479336262

    Returns: 1479336262

  53. 1000000000

    Returns: 1000000000

  54. 9999999998

    Returns: 9999999998

  55. 9999993440

    Returns: 9999993440


This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2024, TopCoder, Inc. All rights reserved.
This problem was used for: