Giter Site home page Giter Site logo

count-coprime-pairs's Introduction

Count Co-Prime Numbers

Sensei will be adding to or removing numbers (x) from a set. 2 numbers in the set are a co-prime pair if and only if gcd(a, b) = 1. As Sensei add or remove numbers from the set, the number of co-prime pairs in the set changes. You are to inform him the latest number of co-prime pairs as that happens.

gcd stands for "greatest common denominator", which is also known as HCF (highest common factor).

Inputs

The first line consists of 1 integer N.
The next N lines each contains 2 numbers, each describing an operation in the form of 1 of the following:

  • 1 x : Sensei is inserting x to the set
  • 2 x : Sensei is removing x from the set (it is guaranteed that x exists in the set)

Outputs

Your output should consist of N lines, each line containing the number of pairs of co-prime numbers in the set.

Sample Tests

Input 1

7
1 1
1 2
1 3
1 5
2 3
1 8
2 8

Output 1

0
1
3
6
3
5
3

Subtasks

For all cases:
1 <= N <= 50000, 1 <= x <= 50000

# Points Constraints
1 20 N <= 100
2 20 x's are all prime numbers
3 30 x's are all powers of prime numbers
4 30 no additional constraint

count-coprime-pairs's People

Contributors

miyagi-sensei avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.