Computer Science, asked by jayashree1698, 10 months ago

Sum of two squares
First, you are given an integer X. You determined the number of ways that you can represent the integer X as the sum of two squares
Now, you represent the number X as the product of N numbers.
If you are given a number N, then represent the product of these N numbers as the sum of two squares.
Input format
• First line: Single integer N denoting the numbers
. Next line: space-separated integers denoting the values of the
numbers
Output format
Output the number of ways of representing the number X as the sum of two squares, where X is the product of N numbers.
Note: Number of ways of representing a number X as sum of two squares can be very large, so output the answer modulo 10' + 7.
Constraints
1<N<200
1<x< 102000
Note: None of the numbers exceed 100
Sample Input
3
2 1 2
Sample Output
4​

Answers

Answered by poojan
0

Language used : Python Programming

Note : Probably, the question should the like product of two squares should be the product of n numbers, as the sum of them is not qualifying the test case you have given.

given numbers [2,1,2] => product = 2*1*2 = 4

Sum of squares of 2 numbers = 2**2 + 1**2 = 4+1 = 5 atleast. So, the output will be zero if we sum up.

If we go for product of squares, the permutations [2,1], [1,2], [2,1], [1,2] are the four possibilities that gives product 4 as answer.

Program :

from itertools import permutations

n=int(input())

prod=1

count=0

x=list(input().split())

if len(x)==n:

   for i in x:

       prod=prod*int(i)

       if int(i)>100:

           print("Number exceeds 100")

           quit()

   y=permutations(x,2)

   for i in y:

       if (int(i[0])**2 * int(i[1])**2) == prod :

           count=count+1

print(count)

Input :

3

2 1 2

Output :

4

Explanation :

  • Take the number of numbers to be considered as input and read them, list them out.

  • Check if any of them are >100, if yes, stop the program there.

  • Else, list out all the 2 ranged permutations and check each permutations multiplication of squares of the each of two elements in it.

  • If it equals the product, increment count by 1.

  • Repeat the same process, till all the permutations are checked.

  • Once the loop terminates, print the count. That's it!

Learn more :

1) Printing all the palindromes formed by a palindrome word.

brainly.in/question/19151384

2) Indentation is must in python. Know more about it at :

brainly.in/question/17731168

3) Write a Python function sumsquare(l) that takes a nonempty list of integers and returns a list [odd,even], where odd is the sum of squares all the odd numbers in l and even is the sum of squares of all the even numbers in l.

brainly.in/question/15473120

Attachments:
Similar questions