結果

問題 No.2119 一般化百五減算
ユーザー kotatsugamekotatsugame
提出日時 2022-11-04 21:42:08
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 65 ms / 2,000 ms
コード長 1,096 bytes
コンパイル時間 843 ms
コンパイル使用メモリ 77,968 KB
実行使用メモリ 4,500 KB
最終ジャッジ日時 2023-09-26 00:00:22
合計ジャッジ時間 2,153 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

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

ソースコード

diff #

#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int N,M;
int val[1<<17];
bool isp[1<<17];
main()
{
	cin>>N>>M;
	for(int i=1;i<=1e5;i++)val[i]=-1;
	for(int i=0;i<M;i++)
	{
		int B,C;cin>>B>>C;
		C=(C%B+B)%B;
		if(val[B]==-1)val[B]=C;
		else if(val[B]!=C)
		{
			cout<<"NaN"<<endl;
			return 0;
		}
	}
	vector<pair<int,int> >Q;
	int mv=0;
	for(int p=2;p<=1e5;p++)if(!isp[p])
	{
		for(int i=p+p;i<=1e5;i+=p)isp[i]=true;
		vector<pair<int,int> >x;
		for(int i=p;i<=1e5;i+=p)if(val[i]!=-1)
		{
			int u=i,t=1;
			while(u%p==0)
			{
				u/=p;
				t*=p;
			}
			x.push_back(make_pair(t,val[i]%t));
		}
		if(!x.empty())
		{
			sort(x.begin(),x.end());
			int C=x.back().second,B=x.back().first;
			for(pair<int,int>p:x)
			{
				if(C%p.first!=p.second)
				{
					cout<<"NaN"<<endl;
					return 0;
				}
			}
			Q.push_back(make_pair(C,B));
			mv=max(mv,C);
		}
	}
	for(int n=mv;n<=N;n++)
	{
		bool ok=true;
		for(pair<int,int>p:Q)
		{
			if(n%p.second!=p.first)
			{
				ok=false;
				break;
			}
		}
		if(ok)
		{
			cout<<n<<endl;
			return 0;
		}
	}
	cout<<"NaN"<<endl;
}
0