//3498 分解质因数
#include <iostream>
#include<cstdlib>using namespace std;
int main()
{
int t,i;
cin>>t;
while(t!=0)
{
int n;
cin>>n;
for(i=2;i<=n;i++)
{
if(n%i==0)
{
cout<<i<<" ";
n=n/i;
i--;
}
}
cout<<endl;
t--;
}
}
//3496 鸡兔同笼
01.
// Problem#: 3496
02.
// Submission#: 3278027
03.
// The source code is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License
05.
// All Copyright reserved by Informatic Lab of Sun Yat-sen University
06.
#include <iostream>
07.
#include<cstdlib>
08.
using namespace std;
09.
10.
int main()
11.
{
12.
int m,n;
13.
cin>>m>>n;
14.
while(m!=0&&n!=0)
15.
{
16.
int x,y;
17.
y=(n-2*m)/2;
18.
x=(4*m-n)/2;
19.
if(m!=(x+y)||x<0||y<0)
20.
cout<<"No answer"<<endl;
21.
else
22.
cout<<x<<" "<<y<<endl;
23.
cin>>m>>n;
24.
}
25.
}
本文提供了一段C++代码实现质因数分解,并通过算法解决了经典的鸡兔同笼问题。质因数分解部分展示了如何将一个整数分解为其所有质因数的乘积;鸡兔同笼问题部分则通过简单的数学运算找出鸡和兔的数量。
890

被折叠的 条评论
为什么被折叠?



