poj1365

數論水題 

 

#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
struct yinzi{int x;int u;}p[200];
void output(int n)
{
	memset(p,0,sizeof(p));

	int top=0;
    if(n%2==0)
	{
	   p[top].x=2;
	   while(n%2==0){p[top].u++;n/=2;}
	   top++;
	}

	for(int i=3;n>1;i+=2)
	{
		if(n%i==0)
		{
			p[top].x=i;
			while(n%i==0){p[top].u++;n/=i;}
			top++;
		}
	}

	printf("%d %d",p[top-1].x,p[top-1].u);
	for(int i=top-2;i>=0;i--)
	{
		printf(" %d %d",p[i].x,p[i].u);
	}
	
		 printf("\n");
	return;
}
int main()
{


	int n;
	int m;int sum;
	char c;
	while(1)
	{
		 cin>>n;
		 if(n==0)break;
		 cin>>m;
		 sum=1;
		 for(int i=0;i<m;i++)sum*=n;
         c=getchar();
		 if(c=='\n')
		 {
			 output(sum-1);
			 continue;
		 }
		 else
		 {
			 while(1)
			 {
				 cin>>n>>m;
				 for(int i=0;i<m;i++)sum*=n;
				 c=getchar();
				 if(c=='\n')
				 {
					 output(sum-1);
					 break;
				 }

			 }
		 }

	}
	return 0;
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章