結果

問題 No.1243 約数加算
ユーザー publflpublfl
提出日時 2020-10-02 22:26:30
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 3 ms / 2,000 ms
コード長 1,027 bytes
コンパイル時間 427 ms
コンパイル使用メモリ 51,896 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-24 21:31:00
合計ジャッジ時間 1,211 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include <stdio.h>
#include <vector>

std::vector<long long int>ans;
std::vector<int> V1,V2;
long long int power(long long int a, int b)
{
	long long int ans = 1;
	for(int i=1;i<=b;i++) ans*=a;
	return ans;
}
int main()
{
	int T;
	scanf("%d",&T);
	while(T--)
	{
		ans.clear();
		V1.clear();
		V2.clear();
		long long int a,b;
		scanf("%lld%lld",&a,&b);
		V1.push_back(0);
		V2.push_back(0);
		for(int i=1;i<=60;i++)
		{
			V1.push_back(a%2);
			a/=2;
		}
		for(int i=1;i<=60;i++)
		{
			V2.push_back(b%2);
			b/=2;
		}
		for(int i=60;i>=1;i--)
		{
			if(V2[i]==1&&V1[i]==0)
			{
				for(int j=1;j<i;j++)
				{
					V1[j+1] += (V1[j]/2);
					V1[j] %= 2;
					if(V1[j]==1)
					{
						ans.push_back(power(2,j-1));
						V1[j]++;
					}
					V1[j+1] += (V1[j]/2);
					V1[j] %= 2;
				}
				if(V1[i]==0) ans.push_back(power(2,i-1));
				for(int j=i-1;j>=1;j--) if(V2[j]==1) ans.push_back(power(2,j-1));
				break;
			}
		}
		printf("%d\n",ans.size());
		for(int i=0;i<ans.size();i++) printf("%lld ",ans[i]);
		printf("\n");
	}
}
0