Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add 2427. Number of Common Factors #40

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions 2427-Number-of-Common-Factors/2427-Number-of-Common-Factors.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
class Solution
{
public:
int commonFactors(int a, int b)
{
int ans=0;
// find the max(a,b)
//iterating over the input
for(int i = 1 ; i <= max(a,b);i++){
//Check condition if a modulus i equal to 0 and b modulus i equal to 0 ans++
if(a%i==0 && b%i==0){
ans++;
}
}
// returning the ans
return ans;
}
};
Empty file.
30 changes: 30 additions & 0 deletions 2427-Number-of-Common-Factors/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<h2><a href="https://leetcode.com/problems/number-of-common-factors/">2427. Number of Common Factors</a></h2><h3>Easy</h3><hr><div><p>Given two positive integers <code>a</code>&nbsp; and <code>b</code>&nbsp;, return the number of <b><em>common</em></b> factors of <code>a</code>&nbsp; and <code>b</code>&nbsp;.

<p>An integer <code>x</code>&nbsp; is a <b>common factor</b> of <code>a</code>&nbsp; and <code>b</code>&nbsp; if <code>x</code>&nbsp;
divides both <code>a</code>&nbsp; and <code>b</code>&nbsp;.



<p>&nbsp;</p>
<p><strong>Example 1:</strong></p>

<pre><strong>Input:</strong> a = 12, b = 6
<strong>Output:</strong> 4
<strong>Explanation:</strong> The common factors of 12 and 6 are 1, 2, 3, 6.
</pre>

<p><strong>Example 2:</strong></p>

<pre><strong>Input:</strong> a = 25, b = 30
<strong>Output:</strong> 2
<strong>Explanation:</strong> The common factors of 25 and 30 are 1, 5.
</pre>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
<li><code>1 &lt;= a, b &lt;= 1000</code></li>
</ul>

</div>