logo Use CA10RAM to get 10%* Discount.
Order Nowlogo
(5/5)

For the integers x in the range x [ LB,UB ], find those x that can be expressed as the sum of one or more distinct squares and show the squares; count those x that cannot be expressed as the sum of one or more distinct squares;

INSTRUCTIONS TO CANDIDATES
ANSWER ALL QUESTIONS

Just fill in missing codes

 

 

For the integers x in the range x [ LB,UB ], find those x that can be expressed as the sum of one or more distinct squares and show the squares; count those x that cannot be expressed as the sum of one or more distinct squares; and distinguish each x as either prime or composite. For example, the results for integers in the range [ 1,30 ] are shown below in the “Sample Program Dialog”.

 

Notes

1 is neither prime nor composite, but can be expressed as the sum of exactly one distinct square, namely, 1 = 1^2

2 and 3 are prime numbers that cannot be expressed as the sum of one or more distinct squares (however 5, 13, 17, and 29 are prime numbers that can be expressed as the sum of one or more distinct squares)

6, 8, 12, 15, 18, 22, 24, 27, and 28 are composite numbers that cannot be expressed as the sum of one or more distinct squares

25, 26, 29, and 30 are composite numbers that can be expressed as the sum of one or more distinct squares and in more than one way!

 

Unfortunately, the claim there are exactly 37 integers in [ 1,149 ] that cannot be expressed as the sum of one or more distinct squares is not true! Run your version of Problem48.c to prove that the claim is not true!  So, then, how many integers and which integers in the range [ 1,149 ] cannot be expressed as the sum of one or more distinct squares?!

 

Sample Program Dialog

LB? 1

UB? 30

      1 = 1^2

*** 1:       2 (prime)

*** 2:       3 (prime)

      4 = 2^2

      5 = 1^2 + 2^2 (prime)

*** 3:       6

*** 4:       7 (prime)

*** 5:       8

      9 = 3^2

     10 = 1^2 + 3^2

*** 6:      11 (prime)

*** 7:      12

     13 = 2^2 + 3^2 (prime)

     14 = 1^2 + 2^2 + 3^2

*** 8:      15

     16 = 4^2

     17 = 1^2 + 4^2 (prime)

*** 9:      18

***10:      19 (prime)

     20 = 2^2 + 4^2

     21 = 1^2 + 2^2 + 4^2

***11:      22

***12:      23 (prime)

***13:      24

     25 = 5^2

     25 = 3^2 + 4^2

     26 = 1^2 + 5^2

     26 = 1^2 + 3^2 + 4^2

***14:      27

***15:      28

     29 = 2^2 + 5^2 (prime)

     29 = 2^2 + 3^2 + 4^2

     30 = 1^2 + 2^2 + 5^2

     30 = 1^2 + 2^2 + 3^2 + 4^2

 

LB? ^Z

Press any key to continue . . .

 

Computational thinking questions. 

 1. Write a for-statement that allows the int-eger x to traverse every int-eger in the int-eger range 

x  [ LB,UB ].

 

 2. What is the variable count counting?! Hint The maximum value of count is (UB-LB+1). 

//-------------------------------------------------------------

// Problem #48

// Problem48.c

//-------------------------------------------------------------

#include <stdio.h>

#include <stdlib.h>

#include <stdbool.h>

 

#include <math.h>

 

#include ".\Combinations.h"

 

//-------------------------------------------------------------

int main()

//-------------------------------------------------------------

{

   bool IsPrime(const int x);

 

   int LB,UB;

 

   printf("LB? ");

   while ( scanf("%d",&LB) != EOF )

   {

      int n;

      int count;

 

      printf("UB? "); scanf("%d",&UB);

      n = (int) (sqrt(UB)+0.5);

      count = 0;

   

      for (int x = LB; x <= UB; x++)

      {

         bool isExpressable = false;

         bool isExpression1 = true;

 

         for (int k = 1; k <= n; k++)

         {

            COMBINATIONS C;

            

            ConstructCombinations(&C,n,k);

            FindFirstCombination(&C);

            do

            {

 

   Student provides missing code to consider all k-combinations, k  [ 1,n ], for each x, then

      display each of the following datums using formats inferred from the "Sample Program Dialog"

 

         (1) x itself;

         (2) x's expression "as the sum of one or more distinct squares" (when applicable);

         (3) the count of xs that cannot be expressed "as the sum of one or more distinct squares"

             (when applicable); and 

         (4) x's prime-ness (when applicable).

 

      *Note* The code that satisfies some of the foregoing requirements is provided both above and below!? 

 

               FindNextCombination(&C);

            } while ( !AtEndOfCombinations(&C) );

            DestructCombinations(&C);

         }

         if ( !isExpressable )

         {

            count++;

            printf("***%2d: %7d",count,x);

            if ( IsPrime(x) )

               printf(" (prime)");

            printf("\n");

         }

      }

      

      printf("\nLB? ");

   }

 

   system("PAUSE");

   return( 0 );

}

 

//-------------------------------------------------------------

bool IsPrime(const int x)

//-------------------------------------------------------------

{

   bool r;

 

   if ( x == 1 )

      r = false;

   else

   {

      r = true;

      for (int i = 2; i <= (int) (sqrt(x)+0.5); i++)

         r = r && (x%i != 0);

   }

   return( r );

}

 

(5/5)
Attachments:

Related Questions

. Introgramming & Unix Fall 2018, CRN 44882, Oakland University Homework Assignment 6 - Using Arrays and Functions in C

DescriptionIn this final assignment, the students will demonstrate their ability to apply two ma

. The standard path finding involves finding the (shortest) path from an origin to a destination, typically on a map. This is an

Path finding involves finding a path from A to B. Typically we want the path to have certain properties,such as being the shortest or to avoid going t

. Develop a program to emulate a purchase transaction at a retail store. This program will have two classes, a LineItem class and a Transaction class. The LineItem class will represent an individual

Develop a program to emulate a purchase transaction at a retail store. Thisprogram will have two classes, a LineItem class and a Transaction class. Th

. SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of Sea Ports. Here are the classes and their instance variables we wish to define:

1 Project 1 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of

. Project 2 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of Sea Ports. Here are the classes and their instance variables we wish to define:

1 Project 2 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of

Ask This Question To Be Solved By Our ExpertsGet A+ Grade Solution Guaranteed

expert
Atharva PatilComputer science

782 Answers

Hire Me
expert
Chrisantus MakokhaComputer science

846 Answers

Hire Me
expert
AyooluwaEducation

619 Answers

Hire Me
expert
RIZWANAMathematics

973 Answers

Hire Me

Get Free Quote!

409 Experts Online