06/02/2017

Number of Divisors Hackerrank Solution in C++ & Geeksforgeeks

Two friends are playing a game. One gives an integer N to the other and asks: What is the number of divisors of N that are divisible by 3? The task is to help the other friend in finding the number of divisors. A number of divisors hackerrank solutions.

Input:
The first line of input contains an integer T denoting the number of test cases. Then T test cases follow. Each test case consists of an integer N.

Output:
For each test case in a new line print the number of divisors.

Number of Divisors Hackerrank Solution in C++


#include <iostream>
using namespace std;
int main()
{
	int t;
	cin >> t;
	while (t--)
	{
		int n, i, count = 0;
		cin >> n;
		for (i = 1; i <= n; i++)
		{
			if (n % i == 0)
			{
				if (i % 3 == 0)
				{
					count++;
				}
			}
		}

		cout << count << endl;
	}

	return 0;

}

The Output of Number of Divisors Hackerrank Solution

The Output of Number of Divisors Hackerrank Solution

Similar to the Number of Divisors


Previous Post
Next Post

post written by:

Hi, I’m Ghanendra Yadav, SEO Expert, Professional Blogger, Programmer, and UI Developer. Get a Solution of More Than 500+ Programming Problems, and Practice All Programs in C, C++, and Java Languages. Get a Competitive Website Solution also Ie. Hackerrank Solutions and Geeksforgeeks Solutions. If You Are Interested to Learn a C Programming Language and You Don't Have Experience in Any Programming, You Should Start with a C Programming Language, Read: List of Format Specifiers in C.
Follow Me

0 Comments: