UVa 11042 Complex, difficult and complicated: an O (1) solution with a very small constant

Source: Internet
Author: User
Tags abs constant

Http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem &problem=1983

The question about the power of the complex number, first of all, from the geometric point of view, a complex can be rotated counterclockwise around the Origin K*arctan (b/a) time after the real number? (The geometrical properties of a complex power)

(Here is a special sentence, when a=0, obviously, n=2)

To do this, arctan (b/a) must be a rational number, and this article shows that this is true if and only if b/a∈{-1,0,1}.

So, as long as the judge b/a whether ∈{-1,0,1} on the line, the others are too complicated.

Complete code:

01./*0.013s*/
.  
#include <cstdio>  
#include <cstdlib>  
.  
06.int Main ()  
07.{  
An    int T, a, B;    scanf ("%d", &t);  
While    (t--)  
.    {        scanf ("%d%d", &a, &b);        if (b = = 0) puts ("1");  
/        Else if (a = = 0) puts ("2");        Else if (abs (a) = = ABS (b)) puts ("4");        else puts ("TOO complicated");  
.    return 0;  
19.}

See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/sjjg/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.