-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path298.c
56 lines (49 loc) · 863 Bytes
/
298.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include <stdio.h>
#include<string.h>
int isPrime(int n)
{
if(n==1) return 0;
int i=2;
for (i=2;i<n/2+1;i++)
{
if(n%i==0) return 0;
}
return 1;
}
int main()
{
int i,f,number;
long long int n;
scanf("%lld",&n);
if (isPrime(n))
{
printf("%d",n);
return 0;
}
i=2;
f=1;
while(i<n+1)
{
number=0;
while(n%i==0)
{
number++;
n/=i;
}
if(number!=0 && f!=1 && number!=1)
printf("*%d^%d",i,number);
if(number!=0 && f!=1 && number==1)
printf("*%d",i);
if(number!=0 && f==1 && number!=1)
{
printf("%d^%d",i,number);
f=0;
}
if(number!=0 && f==1 && number==1)
{
printf("%d",i);
f=0;
}
i+=1;
}
}