Takefumi Yamamura's blog

This blog is for my memorandum.

Takefumi Yamamura's b!og

This blog is for my memorandum

Union Find Tree SRM 703 Middium GCDGraph

Problem Statement

You are given four s: n, k, x, and y.

The s n and k describe a simple undirected graph. The graph has n nodes, numbered 1 through n. Two distinct vertices i and j are connected by an edge if and only if gcd(i, j) > k. Here, gcd(i, j) denotes the greatest common divisor of i and j.

The s x and y are the numbers of two (not necessarily distinct) vertices in our graph. Return "Possible" if it is possible to travel from x to y by following the edges of our graph. Otherwise, return "Impossible".

In other words, return "Possible" if our graph contains a path that connects the nodes x and y, and "Impossible" if there is no such path.

Definition

Class: GCDGraph Method: possible Parameters: int, int, int, int Returns: string Method signature: string possible(int n, int k, int x, int y) (be sure your method is public)

code