Find the sum of the first n composites that do not end in the digit 2. (n = 6 ⇒ 51) using python
code screenshot:


o/p:

code:
# importing the count for infinite loop
from itertools import count
# function will tell if the number is composite or not
def isComposite(num):
# Corner cases
if (num <= 1):
return False
if (num <= 3):
return False
# This is checked so that we can skip
# middle five numbers in below loop
if (num % 2 == 0 or num % 3 == 0):
return True
i = 5
while(i * i <= num):
if (num % i == 0 or num % (i + 2) == 0):
return True
i = i + 6
return False
# driver code
n = int(input('Enter the number of terms: '))
# initialize the counter
counter = n
# initializing the variable to hold the sum
sum_composite = 0
# for loop will execute till infinity until the break condition is interpreted
for num in count():
# check if the number is composite or not
if isComposite(num):
# check if the number ends with 2 or not
if num % 10 != 2:
sum_composite += num
# decrement the counter
counter -= 1
# if the counter becomes 0 break the loop
if counter == 0:
break
# display the sum
print('Sum of first {} composite numbers is: {}'.format(n, sum_composite))
For help please comment. Thank You
Find the sum of the first n composites that do not end in the digit 2....
Find all three-digit numbers with non-zero first digit that are equal to the sum of the cubes of their digits.(FORTON)
Find the sum of the first 23 to the n (23 exponent n) multiples of 23 for a given n using PYTHON. The value of n will not be small. Example (n = 12 ⇒ 5522883785959772985105087173078663)
SOLVE IN MATLAB 11. Find the 5-digit number that satisfies the following properties: a. sum of all the digits is 23 b. sum of the first three digits is 16 c. sum of the first two digits is equal to the third digit d. third digit is twice the fourth digit e. subtracting the fourth digit from the second digit returns the fifth digit
Use a while-end loop in a script file to calculate the sum of the first n terms of the series: sigma_k=1^n (-1)^kl^2 + 5k/3^k. Show the script file and the two results of n = 10 and n = 20. (b) Use a for-end loop in a script file to calculate the sum of the first n terms of the series: sigma_k=1^n (-1)^kl^2 + 5k/3^k. Show the script file and the two results of n = 10 and n =...
a) Find a recurrence relation for an - number of n digit quarternary sequences (using digts from (0, 1,2, 3]) with at least one 1 and the first 1 occurring before the first O.( It is possible that there is no 0 in the sequence). Hint: Consider the cases: the sequence starts with a 1 or with a 2 or with a 3. Note that it cannot start with a O. Explain all steps
a) Find a recurrence relation for...
Use the telescoping series method to find the sum 4 n+2 n + 3 The sum of the series is 2 (Type an exact answer, using radicals as needed.)
write a recursive algorithm to find the sum of the first N terms of the series 1, 1/2, 1/3, ... 1/N
Introduction: Ten digit ISBN numbers are created so that the first nine digits are information digits and the last digit is a check digit. T his last number helps people notice and correct mistakes that might be made in recording the information digits. The same is true for thirteen digit ISBN numbers. Here is a ten digit ISBN number: 0-13-149498-8. The digit 0 indicates the book is written for English-speaking people. The number 13 and the number 149498 identify the...
(do in Java ) The sum of the squares of the first ten natural numbers is, 12 + 22 + ... + 102 = 385 The square of the sum of the first ten natural numbers is, (1 + 2 + ... + 10)2 = 552 = 3025 Hence the difference between the sum of the squares of the first ten natural numbers and the square of the sum is 3025 − 385 = 2640. Find the difference between the...
Use the formula for the sum of the first n integers to evaluate the sum given below, then write it in closed form. A) 6 + 7 + 8 + 9 + ... + 500