結果

問題 No.16 累乗の加算
コンテスト
ユーザー C_kumo
提出日時 2019-01-22 23:51:39
言語 C(gnu17)
(gcc 15.2.0)
コンパイル:
gcc-15 -O2 -std=gnu17 -Wno-error=implicit-function-declaration -Wno-error=implicit-int -Wno-error=incompatible-pointer-types -Wno-error=int-conversion -DONLINE_JUDGE -o a.out _filename_ -lm
実行:
./a.out
結果
TLE  
実行時間 -
コード長 546 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 313 ms
コンパイル使用メモリ 42,324 KB
最終ジャッジ日時 2026-02-22 02:22:13
ジャッジサーバーID
(参考情報)
judge4 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 2 TLE * 1 -- * 11
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

#define ANS (1000000+3)
#define DEV 3

#define DEBUG 0

int main(void)
{
	char x,n,i;
	long a,g,h,j,tmp,ans=0;
	scanf("%hhd %hhd",&x,&n);
	for (i=0;i<n;i++) {
		scanf("%ld",&a);
		
		g = a / DEV;
		h = a % DEV;
		tmp = 1;
		if (DEBUG) printf("g=%ld\n",g);
		for (j=0;j<g;j++) {
			tmp *= pow(x,DEV);
			tmp = tmp % ANS;
		}
		tmp *= pow(x,h);
		tmp = tmp % ANS;

		if (DEBUG) printf("%hhd ^ %ld = %ld\n",x,a,tmp);
		ans += tmp;
		ans = ans % ANS;
	}

	printf("%ld\n",ans);
	
	return 0;
}
0