B - Influence on Social media ,素因子分解,思维,unordered_map

Influence on Social media - Problems - CodeChef

Problem

Recently social media has been flooded by fb posts, tweets, news articles about only thing - demonetization. A great debate is ongoing over it. Most of the people discussing in social media platform usually tend to take sides, i.e. either they support the move, or they not.

There is such a group of N people, who vehemently discuss about their views about this everywhere possible on any platform. The influence of a person is determined by the number of posts he makes. The more posts you make about your support/opposition, more your influence. Usually it is hard to determine whether a person supports/opposes the moves just by reading their posts, as they will make some oblique references here and there, often followed by a big digression into cat-dog memes, and name calling as the final resort, sometimes as a first resort too in rare cases. But you came to know from FB AI team that the people whose support this move behave slightly oddly. Specifically, FB team told that a person will be a supporter if number of divisors of the number of posts a person makes is an odd prime number.

You are given information about number of posts each person makes, specifically person i makes Pi posts. A study about user behavior tells that no-one likes to have same number of posts as the other persons as they consider it as a loss of their identity. So, users make posts in such a way that no two persons have the same number of posts, i.e., all the Pi's are distinct. You want to study the social media strength of users supporting the move. Let K denote the number of supporters of the move. For each i-th most influential supporter, you want to find his/her rank in overall influence in the social media (considering both supporters/opposers).

Input

The first line contains an integer T denoting the number of test cases. T test cases follow.

The first line of each test case contains a single integer N denoting the number of people in the group on social media.

The second line of each test case contains N space separated integers Pi denoting the number of posts made by i-th person.

Output

For each test case, output a single line containing K space separated integers, where i-th of them denotes the overall influence rank of i-th most influential supporter. If K is zero, output "No supporter found." (without quotes) instead.

Constraints

  • 1 ≤ T ≤ 105
  • 1 ≤ N ≤ 105
  • 1 ≤ Pi ≤ 1012
  • Sum of N over all test case ≤ 105

Example

Input:
2
2
1 3
2
13 9

Output: No supporter found. 2

Explanation

Example case 1. There are two persons on the social media group. You can see that first person has made 1 post. As, number of divisors of 1 are 1, which is odd but not a prime, so first person is a opposer of demonetization move. Second person is also opposer of the move, as number of divisors of 3 are 2 (1 and 3), which is even.

As there is no supporter, so the output should be "No supporter found.".

Example case 2. Number of divisors of 13 are 2, which are even. So, person 1 is a opposer of the move. Number of divisors of 9 are 1, 3, 9, which is 3. As 3 is an odd and prime number, person 2 is a supporter of the move. Now, we want to find the overall influence ranking of person 2. We see that person 1 has higher number of posts than person 2. So, influence rank of person 2 will be 2.

解析:

质因数分解:N=p1^c1*p2^c2……pi^ci
显而易见的:N 的因子的个数为:(c1+1)*(c2+1)……(ci+1);
所以我们只需要判断乘积(c1+1)*(c2+1)……(ci+1)是否是素数即可,又因为素数不可能是多个数的乘积,所以 N 若想符合题意,这只能被一个质数分解;
即:N=p1^c1,且 c1+1 为质数
可以先用素数筛将 1e6 范围的素数筛出来,
这里如果预处理后对于每个序列中的数都用直接用遍历去分解则会爆时间;
注意到 pi<=1e12 ,而最小的质数 2^63 已经远远超过 1e12 ,所以我们将所有的先求出所有素数的 c 次幂,一个质素最多也只需要求63次,其中 c 为素数,然后我们只需要将 pi 去匹配即可。

这一将程序的运行时间打印出来看看:vs2019获取代码运行时间(获取时间差ms)_vs2019函数运行时间-CSDN博客

#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;
typedef long long LL;
const int N = 1e5 + 5, M = 1e6 + 5;
int  n;
LL p[N];
int  an[M];
vectorprime;

void init() {
	an[1] = 1;
	for (int i = 2; i < M; i++) {
		if (an[i] == 0)
			prime.push_back(i);
		for (int j = 0; j < prime.size() && prime[j] * i < M; j++) {
			an[prime[j] * i] = 1;
		}
	}
}

int cmp(const LL& a, const LL& b) {
	return a > b;
}

unordered_mapmp;

void init1() {
	for (int i = 0; i < prime.size(); i++) {
		LL t = prime[i];
		for (int j = 3; j < 60; j++) {
			t *= prime[i];
			if (an[j])
				continue;
			if (t > 1e12)
				break;
			mp[t] = 1;
		}
	}
}

int main() {
	int T;
	cin >> T;
	init();
	init1();
	while (T--) {
		scanf("%d", &n);
		LL t;
		for (int i = 1; i <= n; i++) {
			scanf("%lld", &p[i]);
		}
		sort(p + 1, p + 1 + n, cmp);
		int flg = 0;
		for (int i = 1; i <= n; i++) {
			if (mp[p[i]]) {
				flg = 1;
				printf("%d ", i);
			}
		}
		if (!flg)
			printf("No supporter found.");
		printf("\n");
	}
	return 0;
}

你可能感兴趣的:(思维,数论,数学,数论,思维)