1059 Prime Factors (25 point(s))

注:每次修改代码一定要测试一遍。。。 

#include<iostream>
#include<cstdio>
using namespace std;
const int MAXN = 5e5;
int book[MAXN];
int main() {
	for(int i = 2; i < MAXN; ++i)
		for(int j = 2 * i; j < MAXN; j += i) book[j] = 1;
	long int n;
	scanf("%ld", &n);
	bool state = false;
	printf("%ld=", n);
	if(n == 1) printf("1");
	for(int i = 2; n > 1; ++i) {
		int cnt = 0;
		while(!book[i] && n % i == 0) {
			++cnt;
			n /= i;
		}
		if(cnt) {
			if(state) printf("*");
			state = true;
			printf("%d", i);
		}
		if(cnt > 1) printf("^%d", cnt); 
	}
	return 0;
}

 

相关文章:

  • 2021-12-10
  • 2021-05-10
  • 2022-12-23
  • 2022-12-23
  • 2021-09-20
  • 2021-05-22
  • 2021-06-04
  • 2021-07-06
猜你喜欢
  • 2021-06-02
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-08-04
相关资源
相似解决方案