找出幺元和逆元
Time Limit: 1000 ms Memory Limit: 65536 KiB
Problem Description
設I爲整數集,定義二元運算*的運算爲a*b = a+b-k,其中k爲輸入的整數,a,b是集合I內的數,求代數系統V=< I, * >幺元和逆元。
Input
多組輸入,每次輸入兩個正整數k(0<=k<100)和q(0<=q<100),k爲題目中的k,q代表q次詢問,之後輸入q個整數x(0<=x<100).
Output
第一行輸出幺元
接下來輸出q行,爲對應的x的逆元。
Sample Input
25 2 1 3 5 3 4 3 0
Sample Output
25 49 47 5 6 7 10
#include <iostream>
#include <cstdio>
#include <cstdlib>
using namespace std;
int main()
{
int k, q, x, i;
while(~scanf("%d %d", &k, &q))
{
printf("%d\n", k);
for(i = 1; i <= q; i++)
{
scanf("%d", &x);
printf("%d\n", k + k - x);
}
}
return 0;
}