Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

using c++ A sequence of numbers (the heavy sequence) y0y1y2y3...yn...y0y1y2y3...yn... is defined such that each number is the sum of digits squared of the previous

using c++

A sequence of numbers (the heavy sequence)

y0y1y2y3...yn...y0y1y2y3...yn...

is defined such that each number is the sum of digits squared of the previous number, in a particular base.

Consider numbers in base 10, with y0=12y0=12

The next number in the sequence is y1=12+22=5y1=12+22=5

The next number in the sequence is y2=52=25y2=52=25

The next number in the sequence is y3=22+52=29y3=22+52=29

4.1.2 Heaviness

It turns out that for each number y0y0 and base NN, the heavy sequence either converges to 1, or it does not.

A number whose sequence converges to 1 in base N is said to be heavy in base N

4.2 Program requirements

Write a program heavy.cpp that reads a number yy and a base NN from the command line (both of which are written in base-10 notation) and returns whether that number yy is heavy in the base NN provided.

The return code of this program should be 1 if the number is heavy, and 0 if the number is not heavy.

Here are examples:

> heavy 4 10 > echo $? 0
> heavy 2211 10 > echo $? 1
> heavy 23 2 > echo $? 1
> heavy 10111 2 > echo $? 1
> heavy 12312 4000 > echo ?$ 0

4.2.1 Value Ranges

The number yy will always be storable as a normal int, and the base NN will also be storable as a normal int.

The number yy will always be non-negative, and the base NN will always satisfy 2N40002N4000

4.2.2 Restrictions

You may only include the libraries vector and string. No other includes are permitted.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Time Series Databases New Ways To Store And Access Data

Authors: Ted Dunning, Ellen Friedman

1st Edition

1491914726, 978-1491914724

More Books

Students also viewed these Databases questions

Question

Ensure continued excellence in people management.

Answered: 1 week ago