Count of integers
Tag(s):

## Algorithms, Euler's totient function, Greatest common divisor, Math, Number Theory, Sieve

Problem
Editorial
Analytics

You are given a positive integer $n$, for $Q$ queries, You are required to determine the number of integers $k$ ($1 \leq k \leq n$) such that $gcd(k,n)\hspace{2mm}!= 1$ and $gcd(k,n)\hspace{2mm}!= k$.

Input format

• First line: Integer $Q$ denoting the number of queries
• Next $Q$ lines: Integer $n$

Output format

Print $Q$ lines each containing an integer that denotes the answer to that specific query.

Constraints

$1 \leq Q \leq 10^5$

$1 \leq n \leq 10^6$

SAMPLE INPUT
1
10
SAMPLE OUTPUT
3

Explanation

For c = {1,3,7,9} gcd(c,10) = 1

For c = {2,5,10} gcd(c,10) = c

gcd(4,10) = 2

gcd(6,10) = 2

gcd(8,10) = 2

Time Limit: 1,0 sec(s) for each input file.
Memory Limit: 256 MB
Source Limit: 1024 KB
Marking Scheme: Marks are awarded when all the testcases pass.
Allowed Languages: Bash, C, C++, C++14, Clojure, C#, D, Erlang, F#, Go, Groovy, Haskell, Java, Java 8, JavaScript(Rhino), JavaScript(Node.js), Julia, Kotlin, Lisp, Lisp (SBCL), Lua, Objective-C, OCaml, Octave, Pascal, Perl, PHP, Python, Python 3, R(RScript), Racket, Ruby, Rust, Scala, Swift, Swift-4.1, TypeScript, Visual Basic

## CODE EDITOR

Initializing Code Editor...

## This Problem was Asked in Challenge Name

Data Structures and Algorithms coding contest #3

OTHER PROBLEMS OF THIS CHALLENGE
• Algorithms > Searching
Уведомления

?