Skip to content

Commit 810e46c

Browse files
authored
Add files via upload
1 parent 8af2768 commit 810e46c

File tree

1 file changed

+56
-0
lines changed

1 file changed

+56
-0
lines changed

best_approach/get_all_factor.cpp

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
// time complexity of this algo is sqrt(n);
2+
/*
3+
written by pankaj kumar.
4+
*/
5+
#include<algorithm>
6+
#include<string.h>
7+
#include<iostream>
8+
#include<vector>
9+
#include<cmath>
10+
#include<set>
11+
using namespace std;
12+
typedef long long ll ;
13+
typedef vector<int> vi;
14+
typedef vector<pair<int,int>> vpi;
15+
typedef vector<ll> vl;
16+
typedef vector<pair<ll,ll>> vpl;
17+
typedef vector<string> vs;
18+
typedef set<string> ss;
19+
typedef set<int> si;
20+
typedef set<ll> sl;
21+
typedef set<pair<int,int>> spi;
22+
typedef set<pair<ll,ll>> spl;
23+
// macros
24+
#define pan cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);
25+
#define mod 1000000007;
26+
#define phi 1.618
27+
#define line cout<<endl;
28+
/* ascii value
29+
A=65,Z=90,a=97,z=122
30+
*/
31+
32+
int main()
33+
{
34+
int a,count=0;
35+
cout<<"Enter two number : ";
36+
cin>>a;
37+
cout<<"List of all factor of "<<a<<"is : ";
38+
for(int i=1;i<=sqrt(a);i++)
39+
{
40+
if(i%a==0)
41+
{
42+
if(a/i==i)
43+
{
44+
count++;
45+
cout<<i<<" ";
46+
}
47+
else
48+
{
49+
count+=2;
50+
cout<<a/i<<" "<<i;
51+
}
52+
}
53+
}
54+
line;
55+
cout<<"Hence total no of factor of "<<a<<"is "<<count<<endl;
56+
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy