Roy and Shopping
Practice
4.1 (22 votes)
Approved
Easy
Math
Open
Primality test
Problem
77% Success 21177 Attempts 20 Points 1s Time Limit 256MB Memory 1024 KB Max Code

Alfi asked Roy to go for shopping with her. Witty Roy came up with a condition. He said, for each product of MRP (Maximum Retail Price) R, she'll have to pay minimum of all the prime factors of R and he himself will pay rest of the amount. Without giving it a second thought Alfi agreed.

Now they bought N number of products. You're to find how much money did Roy had to pay for each product.

Input:

First line will contain integer N, number of products they bought.

Next N lines each will contain R, MRP of each product.

Output:

Print single integer in a new line, the amount of money Roy had to pay for each product.

Constraints:

2<=N,R<=1000000

Warning: Large I/O. Be careful with certain languages.

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:20
17 votes
Tags:
EasyGrammar-VerifiedMathNumber TheoryPrimality testPrime number
Points:20
52 votes
Tags:
ApprovedEasyMathOpenPrimality test
Points:20
524 votes
Tags:
ApprovedData StructuresEasyHiringSieve