Description
Statements
Ameer is an upcoming and pretty talented problem solver who loves to solve problems using computers. Lately, He bought a very very very large square carpet that has an enormous area, so he stopped amazed as to how large is this carpet exactly… Unfortunately, Ameer has a small length measurement tool, so he can’t measure the area of the carpet as a whole. However, Ameer has a very smart algorithm for folding a square piece of paper reducing it to an exact fraction of its original 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 his algorithm is correct. Also, since the final answer might be incredibly large, Ameer wants to check the remainder of the answer over several prime numbers of his choosing. Can you help Ameer getting the correct answer so that he can compare it with his own ?
Input
For each test case, you would be given three space separated integers on the first line N, K and A respectively, Where N and K are as described earlier and A is the area that Ameer has measured after folding the carpet N times. In the second line there will be an 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 will be a line containing three zeroes separated by a single space. 1 ≤ N, K, A ≤ 231 1 ≤ C ≤ 100 2 ≤ Pi < 231
Output
For each test case you should output on the first line “Case c:” where ‘c’ is the case number, 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
3 3 6
3
41 71 73
0 0 0
Case 1:
39 20 16
比赛时候没模板 也没看懂题目什么意思 感觉智商被掏空....
题意就是把原面积求出来后对后面给的数取模 (然而我看了题目半个小时还不知道是要干什么
拿了学长的一个模板
今天看了岛娘的直播 刚好学长模板也是岛娘那种风格 试了一下 感觉清晰了一点 但感觉还是很不习惯
#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 0x3f3f3f3f
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
typedef 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");
}
}