Ultraviolet A 12103-Leonardo's notebook (number theory replacement group)

Source: Internet
Author: User

Ultraviolet A 12103-Leonardo's notebook

Question Link

Assume that a letter is given to replace B and check whether a causes a ^ 2 = B.

Idea: Any k power of replacement with a length of L splits itself into gcd (L, k) points, and each part has a length of L/gcd (L, k), so the square does not change the length of an odd number, and the even number is split into two cycles with the same length. Therefore, if the number of cycles with an even number in B is not an even number, it is inevitable that a does not exist.

Code:

 
# Include <stdio. h> # include <string. h> const int n = 30; int T, next [N], vis [N], num [N]; char STR [N]; bool judge () {for (INT I = 2; I <= 26; I + = 2) if (Num [I] % 2) return false; return true;} int main () {scanf ("% d", & T); While (t --) {scanf ("% s", STR); For (INT I = 0; I <26; I ++) next [I] = STR [I]-'A'; memset (VIS, 0, sizeof (VIS); memset (Num, 0, sizeof (Num); For (INT I = 0; I <26; I ++) {If (! Vis [I]) {vis [I] = 1; int T = next [I]; int CNT = 1; while (! Vis [T]) {vis [T] = 1; t = next [T]; CNT ++;} num [CNT] ++ ;}} printf ("% s \ n", Judge ()? "Yes": "no");} return 0 ;}


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.