Skip to content

Instantly share code, notes, and snippets.

@RezaBidar
Last active August 29, 2015 14:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save RezaBidar/ec6d8a9c81f5f38148ac to your computer and use it in GitHub Desktop.
Save RezaBidar/ec6d8a9c81f5f38148ac to your computer and use it in GitHub Desktop.
find factors
#include<iostream>
using namespace std ;
int main(){
int a , n , j , tmay = 0 , tedad = 0 ;
cin >> a ;
for( n = 2 ; n <= a && a > 1; n++){
tedad = 0 ;
//in for baraye ine ke bebinim N aval hast ya na
for( j = 2 ; j < n ; j++){
if(n % j == 0)
tedad++ ;
}
//agar n aval bood
if(tedad == 0){
tmay = 0 ;
//ba in halghe tedad bakhshpazirie A ro bar N peyda mikonim
//baraye mesal 84 faghat 2 martabe bar 2 bakhspazire
while( a % n == 0) {
tmay++ ;
a = a / n ;
}
//if bakhshpazir bood chap mikonim
if(tmay > 0){
cout << n << " ^ " << tmay << " * " << endl ;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment