"Chunking" Gym-100923k-por Costel and the Firecracker

Source: Internet
Author: User

Semipal.in/semipal.out

Por Costel The pig, our programmer in-training, have recently returned from the PETROZAPORKSK training camp. There, he learned a lot of things:how to boil a cob, how to scratch his belly using his keyboard, etc ... He almost remembers a programming problem too:

A semipalindrome is a word for which there exists a subword such that's a prefix of and (reverse) is a suffix of. For example, ' Ababba ' are a semipalindrom because the Subword ' ab ' is prefix of ' Ababba ' and ' ba ' are suffix of ' Ababba '.

Let's consider only semipalindromes that contain letters ' a ' and ' B '. You have to find the-th lexicographical semipalindrome of length.

Por Costel doesn ' t remember if the statement is exactly like this on PETROZAPORKSK, but he finds this problem interesting Enough and needs your help to solve it.

Input

On the first line of the file semipal.in, there was an integer () representing the number of test cases. On the next lines there was 2 numbers, (and K where is the number of semipalindromes of length.

Output

In the output file semipal.out, there should is lines, the-th of which should contain the answer for The-th test.

Example

Input
2
5 1
5 14
Output
Aaaaa
Bbabb

Because of the card memory, so the answer can not be all the table, but the answer every 100 minutes, so that only need to open an array of 10w. Then every time you ask, the answer begins with a recent record of violence, no more than 100 times to get the answer.

#include <cstdio>using namespace std; #define MOD 10000003typedef Long long ll;int n,a,b,x1,q,q1;int anss[100010]; int main () {freopen ("pocnitoare.in", "R", stdin), Freopen ("Pocnitoare.out", "w", stdout),//freopen ("K.in", "R", stdin); scanf ("%d%d%d%d%d%d", &n,&a,&b,&x1,&q,&q1); int now=x1;anss[1]=now;for (int i=2;i<= 10000003;++i) {now= ((ll) now* (LL) (i-1)% (ll) n)% (ll) n+ (LL) a% (LL) n)  % (ll) n);  if (i%100==1)    anss[i/100+1]=now;  } int now=anss[q1/100+1];//int tmp=q1%100-1;//for (int i=1;i<=tmp;++i)//  now= (int) (((LL) now* (LL) (i-1)% (LL) N)% (ll) n+ (LL) a% (LL) n)% (ll) n),//printf ("%d\n", now), and for (int i=1;i<=q;++i)  {  if (i!=1)    q1= ((int) (LL ) (i-1) * (LL) now% (LL) MOD) +b%mod)%mod+1;  now=anss[(q1-1)/100+1];for (int j= (q1-1)/100*100+2;j<=q1;++j)    now= (int) (((LL) now* (LL) (j-1)% (ll) n)% (LL) n + (LL) a% (LL) n)% (ll) n);p rintf ("%d\n", now);  } return 0;}

"Chunking" Gym-100923k-por Costel and the Firecracker

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.