結果

問題 No.278 連続する整数の和(2)
ユーザー asugen0402asugen0402
提出日時 2019-06-10 15:13:37
言語 C
(gcc 13.3.0)
結果
AC  
実行時間 20 ms / 2,000 ms
コード長 3,511 bytes
コンパイル時間 270 ms
コンパイル使用メモリ 32,640 KB
実行使用メモリ 17,664 KB
最終ジャッジ日時 2024-10-06 00:40:40
合計ジャッジ時間 1,235 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 18
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#include <float.h>
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
//
#define D_PRM_MAX 1000000 //
#define D_DIV_MAX 1000000 //
// -
typedef struct Prm {
long long mlVal; //
int miCnt; //
} Prm;
//
static FILE *szpFpI; //
static Prm sz1Prm[D_PRM_MAX]; //
static int siPCnt; //
static long long sl1Div[D_DIV_MAX]; //
static int siDCnt; //
// -
#ifdef D_TEST
static int siRes;
static FILE *szpFpA;
static int siTNo;
#endif
//
int
fOut(
char *pcpLine // <I>
)
{
char lc1Buf[1024];
#ifdef D_TEST
fgets(lc1Buf, sizeof(lc1Buf), szpFpA);
if (strcmp(lc1Buf, pcpLine)) {
siRes = -1;
}
#else
printf("%s", pcpLine);
#endif
return 0;
}
//
int
fDivPrm(
long long plVal // <I>
)
{
int i;
//
memset(sz1Prm, 0, sizeof(sz1Prm));
siPCnt = 0;
//
int liLimit = (int)sqrt((double)plVal);
//
for (i = 2; i <= liLimit; i++) {
//
if (plVal == 1) {
break;
}
//
while (plVal % i == 0) {
plVal /= i;
sz1Prm[siPCnt].miCnt++;
}
//
if (sz1Prm[siPCnt].miCnt > 0) {
sz1Prm[siPCnt].mlVal = i;
siPCnt++;
}
}
//
if (plVal != 1) {
sz1Prm[siPCnt].miCnt = 1;
sz1Prm[siPCnt].mlVal = plVal;
siPCnt++;
}
return 0;
}
// -
int
fMakeDivK(
int piPNo // <I> 0
, long long plVal // <I>
)
{
int i;
//
if (piPNo < siPCnt) {
//
for (i = 0; i <= sz1Prm[piPNo].miCnt; i++) {
fMakeDivK(piPNo + 1, plVal);
plVal *= sz1Prm[piPNo].mlVal;
}
return 0;
}
// -
sl1Div[siDCnt] = plVal;
siDCnt++;
return 0;
}
int
fMakeDiv(
long long plVal // <I>
)
{
//
siDCnt = 0;
//
fDivPrm(plVal);
// -
fMakeDivK(0, 1);
return 0;
}
//
long long
fMain(
)
{
int i;
char lc1Buf[1024];
// N -
long long llN;
fgets(lc1Buf, sizeof(lc1Buf), szpFpI);
sscanf(lc1Buf, "%lld", &llN);
if (llN % 2 == 0) {
llN /= 2;
}
// -
fMakeDiv(llN);
// -
long long llSum = 0;
for (i = 0; i < siDCnt; i++) {
llSum += sl1Div[i];
}
return llSum;
}
//
int
fOne(
)
{
long long llRet;
char lc1Buf[1024];
// -
#ifdef D_TEST
sprintf(lc1Buf, ".\\Test\\T%d.txt", siTNo);
szpFpI = fopen(lc1Buf, "r");
sprintf(lc1Buf, ".\\Test\\A%d.txt", siTNo);
szpFpA = fopen(lc1Buf, "r");
siRes = 0;
#else
szpFpI = stdin;
#endif
//
llRet = fMain();
//
sprintf(lc1Buf, "%lld\n", llRet);
fOut(lc1Buf);
//
#ifdef D_TEST
lc1Buf[0] = '\0';
fgets(lc1Buf, sizeof(lc1Buf), szpFpA);
if (strcmp(lc1Buf, "")) {
siRes = -1;
}
#endif
//
#ifdef D_TEST
fclose(szpFpI);
fclose(szpFpA);
#endif
//
#ifdef D_TEST
if (siRes == 0) {
printf("OK %d\n", siTNo);
}
else {
printf("NG %d\n", siTNo);
}
#endif
return 0;
}
//
int
main()
{
#ifdef D_TEST
int i;
for (i = D_TEST_SNO; i <= D_TEST_ENO; i++) {
siTNo = i;
fOne();
}
#else
fOne();
#endif
return 0;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0