Learn DSADSAContests
coding75 logo
LeetCode POTDPOTDSheets
coding75 Pro
coding75 logo
Dashboard
Learn DSA
Course RoadmapFlow
DSA Topic TreeNew πŸš€
Contest SolutionsPractice
Practice Sheets
MasterclassesLive πŸ‘¨πŸ»β€πŸ’»

coding75 ProPRO

Live Classes & Placement Guidance

coding75 logo

The premier developer platform for mastering Data Structures & Algorithms, exploring contest editorials, building ATS-ready resumes, and accelerating your tech career.

Connect & Community

DSA & Contests

  • Learn DSA
  • Contest Solutions
  • LeetCode POTDDaily
  • Practice Sheets
  • MasterclassesSoon

Interview Prep

  • Portfolio Projects
  • CS Fundamentals
  • System DesignSoon
  • Interview ExperiencesSoon
  • Mock InterviewsSoon

Career & Pro

  • Jobs & Internships
  • Resume BuilderATS
  • coding75 Pro
  • Submit Feedback
Β© 2026coding75β€’crackDSAβ„’β€’Maa Lalita Edtech Private Limited. All Rights Reserved.
Privacy PolicyTerms & ConditionsContact Support
Registered Office: Kanpur 208021β€’Regional Office: Indiranagar, Bangalore, 560008
Maa Lalita Edtech Private Limited
Contests/Codeforces/Codeforces Round 950/D. GCD-sequence
PrevNext
CodeforcesCodeforces
Specialist
Codeforces Round 950

D. GCD-sequence

MathArrayGreedyNumber Theory
Loading...
Solve on Codeforces

Problem Statement

Official algorithmic problem description and constraints.

Open on Codeforces

GCD (Greatest Common Divisor) of two integers π‘₯ and π‘¦ is the maximum integer π‘§ by which both π‘₯ and π‘¦ are divisible. For example, πΊπΆπ·(36,48)=12, πΊπΆπ·(5,10)=5, and πΊπΆπ·(7,11)=1.

Kristina has an array π‘Ž consisting of exactly π‘› positive integers. She wants to count the GCD of each neighbouring pair of numbers to get a new array π‘, called GCD-sequence.

So, the elements of the GCD-sequence π‘ will be calculated using the formula π‘π‘–=𝐺𝐢𝐷(π‘Žπ‘–,π‘Žπ‘–+1) for 1β‰€π‘–β‰€π‘›βˆ’1.

Determine whether it is possible to remove exactly one number from the array π‘Ž so that the GCD sequence π‘ is non-decreasing (i.e., π‘π‘–≀𝑏𝑖+1 is always true).

For example, let Khristina had an array π‘Ž = [20,6,12,3,48,36. If she removes π‘Ž4=3 from it and counts the GCD-sequence of π‘, she gets:

  • 𝑏1=𝐺𝐢𝐷(20,6)=2
  • 𝑏2=𝐺𝐢𝐷(6,12)=6
  • 𝑏3=𝐺𝐢𝐷(12,48)=12
  • 𝑏4=𝐺𝐢𝐷(48,36)=12

The resulting GCD sequence π‘ = [2,6,12,12] is non-decreasing because π‘1≀𝑏2≀𝑏3≀𝑏4.

Solutions & Walkthrough

Detailed video explanations, mathematical intuition, and clean C++ implementation code.

Connecting secure classroom stream...
Back to Codeforces Round 950
Previous ProblemNext Problem