結果

問題 No.1409 Simple Math in yukicoder
ユーザー publflpublfl
提出日時 2021-02-26 23:00:52
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 805 ms / 2,000 ms
コード長 1,195 bytes
コンパイル時間 347 ms
コンパイル使用メモリ 52,552 KB
実行使用メモリ 7,424 KB
最終ジャッジ日時 2024-04-10 13:50:44
合計ジャッジ時間 51,581 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,940 KB
testcase_02 AC 3 ms
6,940 KB
testcase_03 AC 3 ms
6,944 KB
testcase_04 AC 3 ms
6,944 KB
testcase_05 AC 3 ms
7,156 KB
testcase_06 AC 4 ms
6,940 KB
testcase_07 AC 136 ms
7,124 KB
testcase_08 AC 498 ms
7,232 KB
testcase_09 AC 153 ms
7,176 KB
testcase_10 AC 391 ms
7,168 KB
testcase_11 AC 545 ms
7,292 KB
testcase_12 AC 387 ms
7,120 KB
testcase_13 AC 143 ms
7,040 KB
testcase_14 AC 127 ms
7,152 KB
testcase_15 AC 179 ms
6,944 KB
testcase_16 AC 220 ms
7,168 KB
testcase_17 AC 730 ms
7,296 KB
testcase_18 AC 333 ms
7,280 KB
testcase_19 AC 361 ms
7,168 KB
testcase_20 AC 295 ms
6,944 KB
testcase_21 AC 240 ms
7,168 KB
testcase_22 AC 467 ms
7,168 KB
testcase_23 AC 100 ms
6,940 KB
testcase_24 AC 76 ms
7,156 KB
testcase_25 AC 463 ms
7,172 KB
testcase_26 AC 480 ms
7,200 KB
testcase_27 AC 805 ms
7,260 KB
testcase_28 AC 755 ms
7,252 KB
testcase_29 AC 800 ms
7,424 KB
testcase_30 AC 805 ms
7,296 KB
testcase_31 AC 759 ms
7,424 KB
testcase_32 AC 805 ms
7,272 KB
testcase_33 AC 750 ms
7,352 KB
testcase_34 AC 766 ms
7,292 KB
testcase_35 AC 797 ms
7,376 KB
testcase_36 AC 795 ms
7,296 KB
testcase_37 AC 747 ms
7,260 KB
testcase_38 AC 733 ms
7,296 KB
testcase_39 AC 747 ms
7,208 KB
testcase_40 AC 739 ms
7,160 KB
testcase_41 AC 758 ms
7,168 KB
testcase_42 AC 749 ms
7,256 KB
testcase_43 AC 752 ms
7,300 KB
testcase_44 AC 735 ms
7,128 KB
testcase_45 AC 728 ms
7,008 KB
testcase_46 AC 741 ms
7,268 KB
testcase_47 AC 733 ms
7,168 KB
testcase_48 AC 748 ms
7,256 KB
testcase_49 AC 732 ms
7,164 KB
testcase_50 AC 762 ms
7,156 KB
testcase_51 AC 743 ms
7,132 KB
testcase_52 AC 727 ms
7,168 KB
testcase_53 AC 722 ms
7,296 KB
testcase_54 AC 740 ms
7,072 KB
testcase_55 AC 733 ms
7,172 KB
testcase_56 AC 760 ms
7,168 KB
testcase_57 AC 63 ms
7,168 KB
testcase_58 AC 62 ms
7,176 KB
testcase_59 AC 62 ms
7,168 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

long long int power(long long int a, long long int b, int p)
{
	long long int ans = 1;
	long long int k = a;
	while(b)
	{
		if(b%2==1) ans*=k, ans%=p;
		k*=k, k%=p;
		b/=2;
	}
	return ans;
}
long long int inv(long long int a, int p)
{
	return power(a,p-2,p);
}

long long int fact[110];
std::vector<int> ans;
long long int check[100010];
std::vector<int> save[1010][110];

int main()
{
	fact[0] = 1;
	int T;
	scanf("%d",&T);
	while(T--)
	{
		ans.clear();
		int a,b;
		scanf("%d%d",&a,&b);
		if(!save[a][b].empty())
		{
			for(int i=0;i<save[a][b].size();i++) printf("%d ",save[a][b][i]);
			printf("\n");
			continue;
		}
		int p = a*b+1;
		
		int count = 0;
		for(int i=1;i<=a*b;i++) check[i] = 0;
		for(int i=1;i<=a*b;i++)
		{
			if(check[i]==0)
			{
				long long int t = power(i,b,p);
				long long int i2 = i;
				long long int s = t;
				
				while(check[i2]==0)
				{
					check[i2] = s;
					if(s==1) count++;
					if(count>=b) goto u;
					i2 = (i2*i)%p;
					s = (s*t)%p;
				}
			}
		}
		u:;
		for(int i=1;i<=a*b;i++) if(check[i]==1) ans.push_back(i);
		save[a][b] = ans;
		for(int i=0;i<ans.size();i++) printf("%d ",ans[i]);
		printf("\n");
	}
}
0