跳到正文

题解

题解:UVA10879 Code Refactoring

Distorted_Fate_约 1 分钟
原文
文章信息与版本

文章信息

发布
2024年8月18日
收录
2025年12月12日
更新
2026年11月14日
篇幅
约 1 分钟
题目
UVA10879

版本

  1. v1当前

题意简述:

给你一个 nn,让你求出它的四个约数。

解法

暴力枚举。

直接从二开始枚举,如果 nn 是这个数的倍数,就每两个一组输出即可。

注意格式。

代码

C++
#include<bits/stdc++.h>
using namespace std;
int t;
signed main(){
	//freopen("a.in","r",stdin);
	//freopen("a.out","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>t;
	while(t--){
		int n;
		cin>>n;
		cout<<"Case #"<<t<<": ";
		cout<<n;
		int cnt=0;
		for(int i=2;i<=n/2;i++){
			if(cnt==2){
				cout<<"\n";
				break;
			}
			if(n%i==0){
				cnt++;
				cout<<" = "<<i<<" * "<<n/i;
			}
		}
	}
	return 0;
}

原文