Question

I got a C++ problem.Let n be a positive integer and let S(n) denote the number of divisors of n. For example, S(1)- 1, S(4)-3, S(6)-4 A positive integer p is called antiprime if S(n)くS(p) for all positive n 〈P. In other words, an antiprime is a number that has a larger number of divisors than any number smaller than itself. Given a positive integer b, your program should output the largest antiprime that is less than or equal to b. Input specification: A positive integer b. For 30% of test cases, b <-100 For 80% of test cases, b < 1000 For 100% of test cases, b < 100000 Output specification: The largest antiprime less than or equal to b. Sample Input Sample Output 12 15 20 24 12 12 12 24

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Here i provide the code snapshot...

main.cpp #include iostream» 2 using namespace std; 3 bool prime(int n) int c-0; for(int 1-2;in/2;1++) 6 8 if((i%2)- 0) 10 12 13 14 15 16 17 return true; eise return falseHere is the output snapshots...

Here are the extra outputs...

Here is the code...

#include <iostream>
using namespace std;
bool prime(int n)
{
int c=0;
for(int i=2;i<n/2;i++)
{
if((i%2)==0)
{ c++;
}
  
}
if(c==0 && n!=1)
return true;
else
return false;
}
int main()
{
int input,k;
cin>>input; //Takes input from user....
int count=0,max=-1;
for(int i=1;i<=input;i++)
{
count=0;
for(int j=1;j<=i;j++)
{
if(i%j==0)
{
count++; //count the numbers of divisors
}
}
if(max < count) //takes the maximum number of divisors
{ if(!prime(i)) //and the number is antiprime
{
max=count;
k=i; //store the number who have greatest number of divisors
}
//cout << "k value is"<<max;
}
}
cout << k<<endl;
//cout << max;
return 0;
}

If you have any doubts please COMMENT

If you understand the answer please give THUMBS UP

Add a comment
Know the answer?
Add Answer to:
I got a C++ problem. Let n be a positive integer and let S(n) denote the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
Active Questions
ADVERTISEMENT