meghana180799

Untitled

Jun 16th, 2019
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.24 KB | None | 0 0
  1. Mr. X is teaching number theory in his class. He is discussing about factors and permutations in his class. A factor of a positive integer N is a positive integer that divides n precisely (without leaving a remainder). The set of factors always includes 1 and N.
  2.  
  3. Mr. X likes combinatorics a lot. He asked his students find out all the factors of the number Y, and sort them in an ascending order. He asks them to list all permutations of the factors. They then need to cross out all permutations where two adjacent numbers are adjacent in the same order in the original list. The number of uncrossed (valid) permutations are to be given to him.
  4.  
  5. Illustration:
  6.  
  7. Integer 9 has 3 factors [1,3,9].
  8.  
  9. The permutations of these factors of number 9 are [1,3,9],[1,9,3],[3,9,1],[3,1,9],[9,1,3],[9,3,1].
  10.  
  11. Of these 6 permutations, we need to cross out [1,3,9] (1 3 adjacent in same order), [3,9,1] (3 9 in same order) and[9,1,3] (1 3 in same order)
  12.  
  13. The remaining (valid) permutations are:
  14.  
  15. [1,9,3] ,[9,3,1],[3,1,9]
  16.  
  17. Hence the number of valid permutations =3, which is the answer.
  18.  
  19. Constraints
  20. 1<= N<=120000
  21.  
  22. 1<=T <= 100
  23.  
  24. Input Format
  25. The first line contains T, the number of testcases
  26.  
  27. Next T lines contain the integer N
  28.  
  29. Output
  30. T lines containing number of valid permutations satisfying conditions mentioned in the problem statement for given input.
  31.  
  32. Test Case
  33.  
  34. Explanation
  35. Example 1
  36.  
  37. Input
  38.  
  39. 1
  40.  
  41. 10
  42.  
  43. Output
  44.  
  45. 11
  46.  
  47. Explanation
  48.  
  49. T=1 (there is 1 test case)
  50.  
  51. N=10.
  52.  
  53. 10 has 4 factors [1,2,5,10]. There are 24 permutations of these four factors. The 11 valid permutations are [1,5,2,10],[1,10,5,2], [2,1,10,5],[2,10,1,5], [2,10,5,1], [5,1,10,2], [5,2,1,10], [5,2,10,1], [10,1,5,2], [10,2,1,5], [10,5,2,1]. Hence the output is 11
  54.  
  55. Example 2
  56.  
  57. Input
  58.  
  59. 2
  60.  
  61. 6
  62.  
  63. 9
  64.  
  65. Output
  66.  
  67. 11
  68.  
  69. 3
  70.  
  71. Explanation
  72.  
  73. T=2 (there are 2 test cases).
  74.  
  75. In the first test case, N=6. 6 has four factors [1,2,3,6]. As in the previous example, there are 11 valid permutations for these. Hence the output for the first test case is 11. This is the first line of the output
  76.  
  77. In the second test case, N=9. As was shown in the Illustration in the problem statement, thenumber of valid permutations is 3. Hence the output for the second test case (the second line of the output) is 3.
Add Comment
Please, Sign In to add comment