Uploaded by wajiwa5144

CP Lab Problem

advertisement
Problem: Q: A mathematician is interested to look
into those numbers which are divisible by p*p also
where p is a prime factor of that number. Given
a number n, write a Program to find the nth such
number.
Example 1. input= 6
Output: 6-th number is 18, and prime factor 3
Example 2: input = 7
Output: 7-th number is 20, and prime factor: 2
Solution:
#include<stdio.h>
int main() {
int count=0, n, ans=0, fac=0;
printf("input= ");
scanf("%d", &n);
for(int i=1; i<10000; i++){
for(int j=1; j<=i; j++){
if(j!=1 && i%j==0 && i%(j*j)==0){
count++;
if(count==n){
ans=i;
fac=j;
}
break;
}
}
printf("");
}
printf("%d-th number is %d, and prime factor:
%d\n", n, ans, fac);
return 0;
}
Download