Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- import java.util.ArrayList;
- import java.util.Scanner;
- public class Problem {
- public static void main(String[] args){
- Scanner sc = new Scanner(System.in);
- int n = sc.nextInt();
- ArrayList<Long> real = new ArrayList<>();
- ArrayList<Long> imaginary = new ArrayList<>();
- for(int i=0; i<n; i++){
- long num = sc.nextLong();
- real.add(num);
- }
- for(int i=0; i<n; i++){
- long num = sc.nextLong();
- imaginary.add(num);
- }
- ArrayList<Long> result = multiplyComplexNumbers(real, imaginary, n);
- System.out.println(result.get(0) + " + (" + result.get(1) + ")i");
- }
- public static ArrayList<Long> multiplyComplexNumbers(ArrayList<Long> real, ArrayList<Long> imaginary, int n){
- ArrayList<Long> result = new ArrayList<>();
- result.add(1L);
- result.add(0L);
- for(int i=0; i < n; i++){
- result = multiply(result.get(0), result.get(1), real.get(i), imaginary.get(i));
- }
- return result;
- }
- public static ArrayList<Long> multiply(long a, long b, long x, long y){
- // ax - by + i(bx + ay)
- long MOD = 1000000007;
- ArrayList<Long> result = new ArrayList<>();
- result.add((a*x - b*y)%MOD);
- result.add((b*x + a*y)%MOD);
- return result;
- }
- }
Add Comment
Please, Sign In to add comment