結果

問題 No.16 累乗の加算
ユーザー myantamyanta
提出日時 2017-05-01 11:43:48
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 2 ms / 5,000 ms
コード長 585 bytes
コンパイル時間 612 ms
コンパイル使用メモリ 47,636 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-08 12:08:43
合計ジャッジ時間 1,475 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,384 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,380 KB
testcase_06 AC 2 ms
4,384 KB
testcase_07 AC 1 ms
4,380 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 ms
4,380 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 1 ms
4,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/*
	No.16 累乗の加算
*/
#include<cstdio>
#include<vector>
#include<algorithm>


using namespace std;


typedef long long ll;


#define MOD 1000003


int main(void)
{
	int x, n, i, j;
	vector<int> a;
	vector<ll> r;
	ll x2, sum;

	while(scanf("%d%d", &x, &n)==2)
	{
		a.resize(n);
		r.resize(n);
		fill(r.begin(), r.end(), 1);
		for(i=0;i<n;i++) scanf("%d", &a[i]);

		x2=x;
		for(i=0;i<27;i++)
		{
			for(j=0;j<n;j++)
			{
				if((a[j]>>i)&1) r[j]=(r[j]*x2)%MOD;
			}
			x2=(x2*x2)%MOD;
		}
		sum=0;
		for(i=0;i<n;i++) sum+=r[i];
		printf("%d\n", (int)(sum%MOD));
	}

	return 0;
}
0