結果

問題 No.1498 Factorization from -1 to 1
ユーザー kotatsugamekotatsugame
提出日時 2021-05-04 13:23:47
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 823 ms / 3,000 ms
コード長 730 bytes
コンパイル時間 828 ms
コンパイル使用メモリ 85,904 KB
実行使用メモリ 15,344 KB
最終ジャッジ日時 2023-09-30 14:58:27
合計ジャッジ時間 6,695 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 3 ms
4,380 KB
testcase_03 AC 171 ms
4,384 KB
testcase_04 AC 823 ms
15,344 KB
testcase_05 AC 655 ms
10,808 KB
testcase_06 AC 666 ms
10,820 KB
testcase_07 AC 660 ms
11,108 KB
testcase_08 AC 660 ms
10,848 KB
testcase_09 AC 668 ms
10,756 KB
testcase_10 AC 10 ms
4,376 KB
testcase_11 AC 9 ms
4,380 KB
testcase_12 AC 9 ms
4,376 KB
testcase_13 AC 9 ms
4,380 KB
testcase_14 AC 9 ms
4,376 KB
testcase_15 AC 2 ms
4,380 KB
testcase_16 AC 2 ms
4,376 KB
testcase_17 AC 2 ms
4,384 KB
testcase_18 AC 2 ms
4,380 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 2 ms
4,376 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 2 ms
4,380 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:9:1: 警告: ISO C++ では型の無い ‘main’ の宣言を禁止しています [-Wreturn-type]
    9 | main()
      | ^~~~

ソースコード

diff #

#include<iostream>
#include<vector>
#include<map>
using namespace std;
const int LIM=100001;
bool isp[LIM+1];
vector<int>ps;
map<long,vector<long> >mp;
main()
{
	for(int i=2;i<=LIM;i++)if(!isp[i])
	{
		for(int j=i+i;j<=LIM;j+=i)isp[j]=true;
		if(i%4!=3)ps.push_back(i);
	}
	int Q;
	cin>>Q;
	for(;Q--;)
	{
		long X;cin>>X;X=X*X+1;
		long long X_=X;
		vector<long>ans;
		if(mp.find(X_)!=mp.end())ans=mp[X_];
		else
		{
			for(int p:ps)
			{
				if((long)p*p>X)break;
				if(X%p==0)
				{
					while(X%p==0)
					{
						ans.push_back(p);
						X/=p;
					}
				}
			}
			if(X>1)
			{
				ans.push_back(X);
			}
		}
		for(int i=0;i<ans.size();i++)cout<<ans[i]<<(i+1==ans.size()?'\n':' ');
		if(mp.find(X_)==mp.end())mp[X_]=ans;
	}
}
0