結果

問題 No.3332 Consecutive Power Sum (Small)
コンテスト
ユーザー pengin_2000
提出日時 2025-11-02 22:17:14
言語 C
(gcc 13.3.0)
結果
AC  
実行時間 25 ms / 2,025 ms
コード長 975 bytes
コンパイル時間 1,046 ms
コンパイル使用メモリ 27,476 KB
実行使用メモリ 11,236 KB
最終ジャッジ日時 2025-11-02 22:17:18
合計ジャッジ時間 2,874 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 52
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c:2:15: warning: conflicting types for built-in function ‘pow’; expected ‘double(double,  double)’ [-Wbuiltin-declaration-mismatch]
    2 | long long int pow(long long int a, long long int n)
      |               ^~~
main.c:2:1: note: ‘pow’ is declared in header ‘<math.h>’
    1 | #include<stdio.h>
  +++ |+#include <math.h>
    2 | long long int pow(long long int a, long long int n)
main.c: In function ‘main’:
main.c:15:9: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   15 |         scanf("%lld", &n);
      |         ^~~~~~~~~~~~~~~~~

ソースコード

diff #

#include<stdio.h>
long long int pow(long long int a, long long int n)
{
	long long int res = 1;
	for (; n > 0; n /= 2, a *= a)
		if (n % 2 > 0)
			res *= a;
	return res;
}
long long int sum[1000006];
long long int ans[1000006][3], c;
int main()
{
	long long int n;
	scanf("%lld", &n);
	long long int e, l, r, w, i;
	for (w = 0; w * w <= 2 * n; w++);
	for (w--; w > 0; w--)
	{
		if (2 * n % w > 0)
			continue;
		i = 2 * n / w;
		if ((i + 1 - w) % 2 == 0)
		{
			l = (i + 1 - w) / 2;
			r = l + w - 1;
			ans[c][0] = 1;
			ans[c][1] = l;
			ans[c][2] = r;
			c++;
		}
	}
	for (e = 2; e < 60; e++)
	{
		sum[0] = 0;
		l = 0;
		for (r = 1; pow(r, e) <= n; r++)
		{
			sum[r] = sum[r - 1] + pow(r, e);
			while (sum[r] - sum[l] > n)
				l++;
			if (sum[r] - sum[l] == n)
			{
				ans[c][0] = e;
				ans[c][1] = l + 1;
				ans[c][2] = r;
				c++;
			}
		}
	}
	printf("%lld\n", c);
	for (i = 0; i < c; i++)
		printf("%lld %lld %lld\n", ans[i][0], ans[i][1], ans[i][2]);
	return 0;
}
0