Last active
August 29, 2015 14:18
-
-
Save RezaBidar/ec6d8a9c81f5f38148ac to your computer and use it in GitHub Desktop.
find factors
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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