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 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...
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
Use the sum/difference identities to simplify the expression. Do not use a calculator. 51 571 COS - + n- ola O A. cos (1) O B. cos (6) OD. cos (5) Find the exact value by using a sum or difference identity. cos 285° 4 OA. - V3 (V3 - 1) O B. V2 (13-1) O C. - 12(73 +1) OD. - v2(13 - 1)
IN C++ Pleaseeeee Write a program to find the sum of the series 1/n+2/n+3/n+4/n+...+n/n, where 1 <= n <= 8 using a function. The user is asked to enter an integer value n. Then the program calls the appropriate function to calculate the sum of the series and then prints the sum to the screen.