1528.cpp

来自「哈尔滨工业大学ACM 竞赛网上在线试题集锦的源代码」· C++ 代码 · 共 31 行

CPP
31
字号
/*  This Code is Submitted by wywcgs for Problem 1528 on 2006-08-10 at 10:54:55 */ 
#include <cstdio>
#include <cmath>
 
typedef long long int64;
 
inline void factor(int64&, int64);
 
int main()
{
	int64 n;
	
	while(scanf("%lld", &n) != EOF && n >= 0) {
		factor(n, 2);
		int64 mid = (int64)(sqrt(n)+1e-6), fact;
		for(fact = 3; fact <= mid && n >= mid; fact += 2) {
			if(n % fact != 0) continue;
			factor(n, fact); mid = (int64)(sqrt(n)+1e-6);
		}
		if(n != 1) printf("%lld\n", n);
		putchar('\n');
	}
	
	return 0;
}
 
inline void factor(int64& n, int64 f)
{
	for(; n % f == 0; n /= f) printf("%lld\n", f);
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?