CSE 232 Fall 2017 Programming Project 03 This assignment is worth 20 points (2%
ID: 3889397 • Letter: C
Question
CSE 232 Fall 2017 Programming Project 03 This assignment is worth 20 points (2% ofthe course grade) and must be completed and turned in before 11:59 on Monday, September 25 This assignment will give you more experience on the use of loops and conditionals, and introduce the use of functions. 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:len wikipedia.oeg/wiki Table of prime factors for a table of the prime factors of many numbers. B-smooth Numbers A number is B-smooth httasen wikincdia.ore/wikilSmooth number if none of greater than the value B. For example, the list of 3-smooth numbers (numbers whose prime factors are S or less) are listed in https:locis.or A051037.30, as seen above, is a 5-smooth number. It would also be 6-smooth, 7-smooth, etc. its prime factors are k-hyperperfect numbers We saw counting the divisors of a number in project 2. Here we are going to sum all the divisors ofa 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 equals 28. These were traditionally called perfect numbers. .21 is 2-hyperperfect. Applying the formula o sum of divisors 2) (1+3+7+21) 32 o The value in parentheses is then (32-21-1)-10 k=2, so 2 * 10=20 20+1= 21. httos:/en.wikipedia org/wiki Hynernerfect number gives a list of k-hyperperfect numbers. Project Description/Specification arnir First, a warning. In this and in all future projects we will provide evactly our function specifications: the function name, its return type, its arguments and each argument's type. The functions will be tested individually in Mimir using these exact function specifications. If you do not follow the functionExplanation / Answer
Given below is the program for the given question along with output. Please don't forget to rate the answer if it helped. Thank you very much.
#include <iostream>
using namespace std;
long biggest_prime(long n); //return the largest prime factor of n
long sum_of_divisors(long n); //sums up all divisors of n
// retursn the 1st k in the range 1 - k_max for which n is k-hyperperfect
//returns 0 if no such k in range 1 - k_max
long k_hyperperfect(long n, long k_max);
bool b_smooth(long n, long b); //returns true if n is b smooth , false otherwise
int main()
{
long n, k_max, b;
cout << "Enter n: ";
cin >> n;
cout << "Enter k_max: ";
cin >> k_max;
cout << "Enter b: ";
cin >> b;
cout << biggest_prime(n) << " ";
cout << sum_of_divisors(n) << " ";
cout << k_hyperperfect(n, k_max) << " ";
cout << boolalpha << b_smooth(n, b) << endl;
}
long biggest_prime(long n)
{
long prime = 2;
while(n > 1)
{
if(n % prime == 0) //check if the number is divisible by current prime
n /= prime;
else //otherwise check with next prime
prime++;
}
return prime;
}
long sum_of_divisors(long n)
{
long sum = 0;
for(int i = 1; i <= n; i++) //for all numbers from 1 to n
{
if(n % i == 0) //check if i divides n, then its a divisor , so add it
{
sum += i;
}
}
return sum;
}
long k_hyperperfect(long n, long k_max)
{
long sum = sum_of_divisors(n);
long rhs;
for(int k = 1; k <= k_max; k++)
{
rhs = 1 + k * (sum - n - 1);
if(n == rhs) //found a k satisfying the condition for k_hyperperfect, so return it
return k;
}
return 0; //no such k, so return 0
}
bool b_smooth(long n, long b)
{
if(biggest_prime(n) < b)
return true;
else
return false;
}
output
Enter n: 21
Enter k_max: 20
Enter b: 10
7 32 2 true