C++ code only please and comments would help CSE 232 Fall 2017 Programming Proje
ID: 3889648 • Letter: C
Question
C++ code only please and comments would help
CSE 232 Fall 2017 Programming Project 03 This assignment is worth 20 points (2% of the course grade) and must be completed and turned in before 11:59 on Monday, September 25th. Assignment Overview This assignment will give you more experience on the use of loops and conditionals, and introduce the use of functions Background There are all sorts of special numbers. Take a look sometime at http://mathworld.wolfram.com/topics/SpecialNumbers.html for a big list. We are going to look at two classes of special numbers: k-hyperperfect numbers and smooth numbers Prime Factors The prime factors of any integer should be familiar. You find all the prime integers that divide exactly (without remainder) into an integer. We exclude 1 (which is a factor of every integer) and the number itself (which, again, is a prime factor of every particular number) for example, the prime factors of 30 are 2,3,5 since 2*3*5-30. Note that 6, 15 and 10 are also factors but they are not prime factors take a look at https://en.wikipedia.org/wiki/Table of prime factors for a table of the prime factors of many numbers » B-smooth Numbers A number is B-smooth https://en.wikipedia.org/wiki/Smooth number if none of its prime factors are greater than the value B. For example, the list of 5-smooth numbers (numbers whose prime factors are 5 or less) are listed in https://oeis.org/A051037. 30, as seen above, is a 5-smooth number. It would also be 6-smooth, 7-smooth, etc k-hyperperfect numbers We saw counting the divisors of a number in project 2. Here we are going to sum all the divisors of a number. A number n is k hyperperfect for some k if the following equality holds: n = 1 + k*(sum-of-divisors(n)-n-1) For example, 28 is 1-hyperperfect, meaning that the sum of its divisors (1+2+4+7+14+28) minus the 28 itself minus 1 equals 28. These were traditionally called perfect numbers . 21 is 2-hyperperfect. Applying the formula sum of divisors(21)-(1+3+7+21)=32 The value in parentheses is then (32-21-1) = 10 k=2, so 2 * 10=20 o o 20 +1-21 https://en.wikipedia.org/wiki/Hyperperfect number gives a list of k-hyperperfect numbersExplanation / Answer
#include<iostream>
using namespace std;
void B_smooth(int n)
{
int i=2;//starting with prime number 2
cout<<"B-smooth of "<<n<<" :";
while(n>0)//loop runs upto n==1
{
if(n%i==0)//if prime number is factor of n
{
n=n/i;//dividing wid prime number
}
else i++; //incrementing i
if(n==1)break;
}
int j;
while(i>0)
{
for(j=2;j<i;j++)
{
if(i%j==0)break;
}
if(j==i)
{
cout<<i<<" ";
break;
}
i++;
}
cout<<" ";
}
void print_primefactors(int n)
{
int i=2;//starting with prime number 2
cout<<"Prime factors of "<<n<<" :";
while(n>0)//loop runs upto n==1
{
if(n%i==0)//if prime number is factor of n
{ cout<<i<<" ";//printing prime factor
n=n/i;//dividing wid prime number
}
else i++; //incrementing i
if(n==1)break;
}
cout<<" ";
}
int main()
{
int n;
cout<<"Enter numbers to find prime factors :";//asking user input..
cin>>n;//reading number
print_primefactors(n);//calling function...
B_smooth(n);
return 0;
}
output:-
Enter numbers to find prime factors :30
Prime factors of 30 :2 3 5
B-smooth of 30 :5
Process exited normally.
Press any key to continue . . .
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.