
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Print N lines of numbers such that every pair among numbers has a GCD K
GCD
GCD stands for Greatest Common Divisor of two or more integers excluding 0
Like, to find the greatest common divisor of 48 and 180
48 = 2 × 2 × 2 × 2 × 3
180 = 2 × 2 × 3 × 3 × 5
Greatest common divisor = 2 × 2 × 3 = 12.
In the given problem, N lines should be printed with elements have GCD as specified
Input : N=2 GCD=2 Ouput : 2-4-6-10 14-16-18-22
Algorithm
START Step 1 -> take input n(e.g. 2) and k(e.g. 2) as int values and i Step 2-> Loop For i to 0 and i<n and i++ Print (k * (6 * i + 1)) Print (k * (6 * i + 2)) Print (k * (6 * i +3)) Print (k * (6 * i + 5)) Print \n Step 3 -> end loop STOP
Example
#include<stdio.h> int main() { int i,n = 2, k = 2; for (i = 0; i < n; i++) { printf("%d-",(k * (6 * i + 1))); printf("%d-",(k * (6 * i + 2))); printf("%d-",(k * (6 * i + 3))); printf("%d",(k * (6 * i + 5))); printf("\n"); } return 0; }
Output
if we run above program then it will generate following output.
2-4-6-10 14-16-18-22
- Related Questions & Answers
- Find original numbers from gcd() every pair in C++
- Find original numbers from gcd() every pair in Python
- Print n numbers such that their sum is a perfect square
- Place N^2 numbers in matrix such that every row has an equal sum in C++
- Maximum sum of distinct numbers such that LCM of these numbers is N in C++
- Print all distinct integers that can be formed by K numbers from a given array of N numbers in C++
- Program to print numbers such that no two consecutive numbers are co-prime and every three consecutive numbers are co-prime Using C++
- Find GCD of two numbers
- Print numbers with digits 0 and 1 only such that their sum is N in C Program.
- Count of all N digit numbers such that num + Rev(num) = 10^N - 1 in C++
- Maximum value K such that array has at-least K elements that are >= K in C++
- C++ Program to Find the GCD and LCM of n Numbers
- Print all increasing sequences of length k from first n natural numbers in C++
- Count number of pairs (A <= N, B <= N) such that gcd (A , B) is B in C++
- Find minimum x such that (x % k) * (x / k) == n in C++
Advertisements