0% found this document useful (0 votes)
28 views

Accenture CodingPart4

The fewest number of perfect square numbers that add up to 12 is 3, since 1 + 4 + 9 = 12. Input: n=13 Output: -1 Explanation: It is not possible to write 13 as a sum of perfect square numbers.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views

Accenture CodingPart4

The fewest number of perfect square numbers that add up to 12 is 3, since 1 + 4 + 9 = 12. Input: n=13 Output: -1 Explanation: It is not possible to write 13 as a sum of perfect square numbers.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Problem Statement: Divisibility Check

Implement the function: int NearestInteger(int num, int m);


The function accepts two positive integers ‘num’ and ‘m’ as its arguments. Implement the function to find and return a number which satisfies below conditions.
1. Number is divisible by ‘m’.
2. Number is nearest to ‘num’. (have the least distance from num)
Distance between two numbers is the number of integers between them.
Note: If there are two numbers with the least distance from ‘num’ which is divisibly by ‘m’ then return the larger number.
Example:
Example:
Input:
Input:
num: 67
num: 26
m: 8
m: 3
Output: 64
Output:
27
Explanation: Nearest Number greater than 67 which is divisible by 8 is 72. Nearest Number less than 67 which is divisible by 8 is 64. Since, 64 is nearest to 67. Thus, output is 64.
Problem Statement:
Implement the following function: def CommonDigit(a,b,c):
The function accepts three positive integers ‘a’, ‘b’, and ‘c’ as its arguments. Implement the function to find and return the common digit in all the three numbers, if there is no common digit then return -1.
Assumption:
 All 3 numbers are three digit numbers.
 All 3 numbers can have at most 1 digit common.
Example:
Input:
a : 426
b : 486
c : 652
Output:
6
Explanation: 6 is common digit in all three numbers.
Example:
Input:
a : 579
b : 394
c : 955
Output: 9.
Problem Statement:

Print the pattern: You have been given the number of rows: n=5

*****
****
***
**
*
Problem Statement: Print the pattern.
Given below is the cross pattern has the shape of the mathematical cross sign (X).
For n=5

* *
**
*
**
* *
Problem Statement:
Ann recently began using the metro to work. We are aware that a single ride on the metro costs one ruble. Ann also learned that she can purchase a unique ticket for the rides ( she can buy it
several times). The price is b rubles. Ann calculated that she would need to take the subway n times. Help Ann out by letting her know how much money she must have in order to buy n rides.
Input:
The four numbers n, m, a, b (1 <= n , m, a, b <= 1000) on a single line represent the number of rides Ann has scheduled, the number of rides covered by the m ride ticket, the cost of a one ride
ticket, and the cost of a m ride ticket.
Output: Print a single integer –the minimum sum in rubles that Ann will need to spend.
Input:
6212
Output:
6

Input:
5223
Output:
8
Problem Statement:

Return the fewest number of perfect square numbers that add up to n, given n integer n.

An integer that is the square of another integer, or the product of another integer and itself, is referred to as perfect square. For instance while 3 and 11 are not perfect
square, 1, 4, 9 and 16 are.

Input: n=12
Output: 3

You might also like