CodeChef is a non-commercial competitive programming community
Login
Username (New User? Signup) Password (Forgot Password?)
Signup
Login or
Signup with
Connect
Note
  • Publicize your achievements on your Facebook Wall.
  • Challenge your friends or ask them for help.

Site Navigation

  • PRACTICE
    • Easy
    • Medium
    • Hard
    • Challenge
    • Peer
  • COMPETE
    • February CookOff
    • February Long Contest
    • January CookOff
  • DISCUSS
    • Wiki
    • Forums
    • Blog
    • Twitter
  • COMMUNITY
    • CodeChef Meetups
    • Campus Chapters
    • Host your Contest
    • User Groups
    • CodeChef TechTalks
    • All Educational Initiatives
    • Event Calendar
  • HELP
    • Frequently Asked Questions
    • FAQ for problem setters
    • Problem Setting
    • Ranks
    • Tutorials
  • ABOUT
    • About CodeChef
    • Team CodeChef
    • Press Room
    • CodeChef Financials
    • CodeChef Sponsorships
    • CEO's Corner
    • Contact Us
    • About Directi
Home » Compete » Manthan 2010 » GCRD

GCRD

Problem code: CF04

  • All Submissions

All submissions for this problem are available.

Greatest Common Right Divisor for two square matrices A and B is a matrix 'D' which satisfies following 3 conditions:

  1. A = P * D
  2. B = Q * D
  3. D = X * A + Y * B

where P, Q, X and Y are some matrices.
The task is to output the matrices D, X and Y for the given square matrices A and B.

Input

Input file will contain multiple input cases each denoting a combination of matrices A and B. First line of the input file consists of an integer t (around 20) denoting the no. of test cases.

Each input case will consist of:

  1. First line of the test will contain a single integer N(<=100) denoting the size of matrices A and B.
  2. Next N lines will contain the corresponding row elements of Matrix A each separated by a blankspace.
  3. Further N lines will contain the corresponding row elements of Matrix B each separated by a blankspace.

Output

For each input case, output the following:

  1. First N lines contain corresponding row elements of Matrix D each separated by a blankspace.
  2. Further N lines contain corresponding row elements of Matrix X each separated by a blankspace.
  3. Last N lines contain corresponding row elements of Matrix Y each separated by a blankspace.

Print a new line after each output.

Example

Input:
2
1 2
3 4
4 3
2 1
3
1 2 3
4 5 6
7 8 9
3 4 5
6 7 8
2 5 7

Output:
1 2 
0 -1 
1 0 
3 2 
4 5 
2 3 
1 0 
2 -2 
0 0 
1 0
 
1 2 3 
0 1 1 
0 0 -1 
1 0 0 
4 -3 3 
7 -6 6 
3 -2 2 
6 -5 5 
2 1 0 
1 0 0 
-2 0 0 
-2 0 0 
0 0 0 
0 0 1 
-2 1 1 


Date: 2010-03-26
Time limit: 3s
Source limit: 50000
Languages: C C++ 4.0.0-8 C++ 4.3.2


  • Submit

Comments

  • Login or Register to post a comment.

There is an update in this

manthan @ 28 Mar 2010 06:03 PM
There is an update in this problem. Number of test cases, t <=100. N<=15. Each of the elements in the matrices A and B can only be 1 or 2. Sample Input 2 2 1 2 1 1 1 2 2 1 3 1 2 1 1 1 1 1 2 1 2 1 1 2 2 2 2 1 2 Sample Output 1 2 0 -1 1 0 -1 1 0 0 0 0 1 2 1 0 -1 0 0 0 -1 1 0 0 -1 1 0 1 -3 0 0 0 0 0 0 0 1 0 0

Sample Input 2 2 1 2 1 1 1

manthan @ 28 Mar 2010 06:11 PM
Sample Input
2
2
1 2
1 1
1 2
2 1
3
1 2 1
1 1 1
1 2 1
2 1 1
2 2 2
2 1 2

Sample Output
1 2
0 -1
1 0
-1 1
0 0
0 0

1 2 1
0 -1 0
0 0 -1
1 0 0
-1 1 0
1 -3 0
0 0 0
0 0 0
1 0 0

Current ranking is available

manthan @ 28 Mar 2010 08:08 PM

Current ranking is available at http://www.codechef.com/teams/list/MANTH10/

How answer should be

dzhulgakov_team @ 28 Mar 2010 08:52 PM

How answer should be selected? Obviously, there are infinitely many answers: if (D,X,Y) satisfy the equation than (kD,kX,kY) for real x would also satisfy. Or does it mean that we should found any answer?

Are all elements of all these

ForEver @ 28 Mar 2010 09:05 PM

Are all elements of all these matrices integers?(include P,Q,X,Y,D)

@ForEver: Yes. All the

manthan @ 28 Mar 2010 09:36 PM

@ForEver: Yes. All the elements of all the matrices P, Q, X, Y and D are integers.

@dzhulgakov: There is only one solution possible for each problem.

Note that D is the greatest

manthan @ 28 Mar 2010 09:47 PM

Note that D is the greatest common right divisor. :)

But answer seems not to be

dzhulgakov_team @ 28 Mar 2010 09:49 PM

But answer seems not to be unique! For example I generated thousand of different answers for the first test case. Here is one of them:

D =

2 1

1 1

X =

3 0

3 1

Y =

-3 1

-3 0

P =

-1 3

0 1

Q =

-1 3

1 0

There are thousand of different solutions (probably, infinitely many) where all five matrices are integer-valued.

Is it enough to print any solution?

@CodeFest: what does it mean

dzhulgakov_team @ 28 Mar 2010 09:51 PM

@CodeFest: what does it mean "Greatest" for matrices? :)

Obviously if (P,Q,D,X,Y) is a

Anton_Lunyov_MANTH10 @ 28 Mar 2010 10:18 PM

Obviously if (P,Q,D,X,Y) is a solution then (PU-1,QU-1,UD,UX,UY) is also solution for any unimodular matrix U (with det(U)=1). But there infinitle many unimodular matrix of any order n>1.

GCRD(V1, V2) is a common

manthan @ 28 Mar 2010 10:48 PM
GCRD(V1, V2) is a common right divisor of V1 and V2 (that is, V1 = W1*GCRD(V1, V2) and V2 = W2*GCRD(V1, V2) for some W1
and W2), and any common right divisor of V1 and V2 is a right divisor of GCRD(V1, V2).

May be we need to find

Anton_Lunyov_MANTH10 @ 28 Mar 2010 11:23 PM

May be we need to find upper-triangular GCRD with elements on diagonal d[1],d[2],...,d[n] such that d[i] divides d[i+1], as I see from yout answers. But even in that case it is not always unique.

@CodeFest: Even if the

contest_crasher @ 28 Mar 2010 11:24 PM

@CodeFest: Even if the greatest common right divisor is unique, X and Y are definitely not. Note in the last input case we could have had

X =

0 0 1
-1 1 0
1 -3 0

 

instead.

I also think the answer are

ForEver @ 28 Mar 2010 11:35 PM

I also think the answer are not unique..

Yes, after reviewing the

manthan @ 28 Mar 2010 11:44 PM

Yes, after reviewing the question statement again, we conclude that there may be mutiple solutions possible. So this question is cancelled. Please do not try solving this question. Sorry for the inconvenience.

Rankign will be done on the basis of the other three questions only.

What a pity , and what a

ForEver @ 28 Mar 2010 11:49 PM

What a pity , and what a great thing!

I study Matrix during the past 3 hours and try to solve this. :)

It's 2:20 AM in my time zone , so I have to sleep ..

good...go to sleep..

ankit_agrawal @ 28 Mar 2010 11:55 PM
good...go to sleep..

SUCCESSFUL SUBMISSIONS FOR THIS PROBLEM:

Programming Competition Fetching successful submissions
Directi Go for Gold
CodeChef is a global programming communityCodeChef hosts online programming competitions
CodeChef is a non-commercial competitive programming community
  • About CodeChef
  • About Directi
  • CEO's Corner
  • C-Programming
  • Programming Languages
  • Contact Us
© 2009 Directi Group. All Rights Reserved. CodeChef uses SPOJ © by Sphere Research Labs
In order to report copyright violations of any kind, send in an email to copyright@codechef.com
CodeChef a product of Directi
The time now is:
CodeChef - A Platform for Aspiring Programmers

CodeChef was created as a platform to help programmers make it big in the world of computer programming. At CodeChef we work hard to revive the geek in you by hosting programming contests on a monthly basis. We also aim to have training sessions and events related to online programming for programmers around the world. Apart from providing a platform for programming competitions, CodeChef also has various tutorials and forum discussions to help those who are new to the world of computer programming.

Practice Section - A Place to hone your 'Computer Programming Skills'

Try your hand at one of our many practice problems and submit your solution in a language of your choice. Our judge accepts solutions in over 35+ programming languages. Online programming was never this much fun! Receive points, and move up through the CodeChef ranks. Use our practice section to better prepare yourself for the multiple programming competitions that take place through-out the month on CodeChef.

Compete - Monthly Programming Contests and Cook-offs

Here is where you can show off your computer programming skills. Take part in our 10 day long monthly programming contests and the shorter format Cook-off programming contests. Put yourself up for recognition and win great prizes. Prizes worth up to Rs.20,000 and $700 are up for grabs every month along with lots more CodeChef goodies.

Discuss

Are you new to computer programming? Do you need help with algorithms? Then be part of CodeChefs Forums and interact with all our programmers love helping out other programmers and share their ideas.

CodeChef Community

As part of our Educational initiative, we give institutes the opportunity to associate with CodeChef in the form of Campus Chapters. Hosting online programming competitions is not the only feature on CodeChef. Be a part of the CodeChef community through CodeChef meetups and techtalks. You can also host a programming contest for your institute on CodeChef and be a guest author on our blog.

Domain Name Registration, Web hosting, and Website Design provided by BigRock.com