Codeforces Gym 100935D Enormous Carpet fast power modulo

Source: Internet
Author: User

enormous CarpetTime limit:2000MS Memory Limit:65536KB 64bit IO Format:%i64d &%i64 U Gym 100935D

Description

Standard Input/output
Statements

Ameer is a upcoming and pretty talented problem solver who loves to solve problems using computers. Lately, he bought a very very very large square carpet that have an enormous area, so He stopped amazed as to how large are This carpet exactly ... Unfortunately, Ameer have a small length measurement tool, so he can ' t measure the area of the carpet as a whole. However, Ameer have a very smart algorithm for folding a square piece of paper reducing it to an exact fraction of it orig Inal size, and then he came up with another intelligent algorithm for measuring the area of the carpet. Ameer decided to fold the carpet N times, each time reducing it to 1/k of its remaining area, after that he would measure The remaining area of the carpet and apply his algorithm to calculate the original area. As Ameer is still a beginner problem solver He wants to check whether he algorithm is correct. Also, since the final answer might be incredibly large, Ameer wants to check the remainder of the answer overSeveral prime numbers of his choosing. Can Ameer getting the correct answer so the he can compare it with his own?

Input

For each test case, you would is given three space separated integers on the first line N, K and A respectively, Where N a nd K is as described earlier and A is the area that Ameer have measured after folding the carpet N times. The second line there would be a integer number C. The third line contains C integer prime numbers where the i-th number is called Pi. After the last test case, there'll is a line containing three zeroes separated by a single space. 1≤ N, K, A ≤231 1≤ C ≤100 2≤ Pi < 2

Output

For each test case you should output to the first line "Case C:" Where ' C ' was the case number and then one line containing ' C ' Space separated integers on a line where the i-th integer is the remainder of the original area over Pi

Sample Input

Input
3 3 6
3
41 71 73
0 0 0
Output
Case 1:
39 20 16


No template at the time of the game and did not read the question of what it means to feel IQ is hollowed out ....
Test instructions is to find out the original area after the number of the back to the model (but I read the topic for half an hour I do not know what to do


Today saw the island Niang live just as seniors template is also island Niang that style try to feel clear a little but feel still very unaccustomed


#include <iostream> #include <cstring> #include <cstdio> #include <algorithm> #include < queue> #include <vector> #include <iomanip> #include <math.h> #include <map>using namespace STD; #define FIN freopen ("Input.txt", "R", stdin), #define FOUT freopen ("Output.txt", "w", stdout); #define INF 0x3f3f 3f3f#define Lson l,m,rt<<1#define Rson m+1,r,rt<<1|1typedef long Long LL;    ll Fastpow (ll a,ll b,ll c,ll MoD) {ll res = A;        while (c) {if (C & 1) res = (res * b)% MoD;        b = (b * b)% MoD;    C >>= 1; } return res% mod;}    int main () {//fin int cas = 1;    LL N, K, A;        while (~SCANF ("%i64d%i64d%i64d", &n, &k, &a)) {if (n = = 0 && k = = 0 && a==0) break;        int C;        LL num[110];        scanf ("%d", &c);        for (int i = 0;i < C; i++) scanf ("%i64d", &num[i]);        printf ("Case%d:\n", cas++); for (int i = 0;i < C; i++) {if (i = = 0) printf ("%i64d", Fastpow (A, K, N, Num[i]));        else printf ("%i64d", Fastpow (A, K, N, Num[i]));    } printf ("\ n"); }}

  

Codeforces Gym 100935D Enormous Carpet fast power modulo

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.