QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#125235#6512. Completely Multiplicative FunctionUNos_maricones#RE 0ms0kbC++171.7kb2023-07-16 08:32:132023-07-16 08:32:14

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-16 08:32:14]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2023-07-16 08:32:13]
  • 提交

answer

#include<bits/stdc++.h>

using namespace std;

void solve()
{
	int n, k;
	scanf("%d %d", &n, &k );

	if( ( n - k ) % 2 )
	{
		puts("-1");
		return;
	}

	vector< bool > is_prime( n + 1, true );
	vector< int > div( n + 1, -1 );

	vector< int > primes;

	for( int i = 2; i <= n; ++ i )
	{
		if( is_prime[ i ] )
		{
			primes.push_back( i );
			for( int x = 2 * i; x <= n; x += i )
				is_prime[x] = false, div[x] = i;
		}
	}


	if( n <= 76 )//n is also small
	{
		vector< int > sp, gp;
		for( auto p : primes )
		{
			if( 2 * p <= n ) sp.push_back( p );
			else gp.push_back( p );
		}

		const int m = (int) sp.size();
		const int del = (int) gp.size();
		
		vector< int > f ( n + 1, 1 );
		for( int mask = 0; mask <	( 1 << m ); ++ mask )
		{
			for( int i = 0; i < m; ++ i )
			{
				if( mask >> i & 1 )
					f[sp[i]] *= -1;
			}

			for(int i = 2; i <= n; ++ i )
				if( !is_prime[i] )
					f[i] = f[div[i]] * f[i/div[i]];

			int sum = 0;
			for( int i = 1; i <= n; ++ i )
				sum += f[i];

			const int rem = sum - k;
			if( rem >= 0 && rem <= 2 * del )
			{
				for( int i = 0; i < rem; ++ i )
					f[gp[i]] = -1;

				for( int i = 1; i <= n; ++ i )
					cout << f[i] << " \n"[i==n];
				return;
			}
		}

		puts("-1");
		return;
	}

	int rem_minus = ( n - k ) / 2;

	vector< int > f( n + 1, 1 );
	for( auto p : primes )
	{
		if( 1LL * p * p > n &&  rem_minus >= ( n / p ) )
		{
			rem_minus -= ( n / p );
			for( int i = 1; i * p <= n; ++ i )
				f[i*p] *= -1;
		}
	}

	
	for( int i = 1; i <= n; ++ i )
		cout << f[i] << " \n"[i==n];
}

int main()
{
	int t;
	scanf("%d", &t );
	while( t-- )
		solve();

	return 0;
};

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Runtime Error

input:

4
4 2
10 0
10 1
10 10

output:


result: