| Time Limit: 1000MS | Memory Limit: 10000K | |
| Total Submissions: 3085 | Accepted: 1415 |
Description
The sequence
(e kx, e kx-1, ... ,e 1, e 0)
is considered to be the representation of x in prime base number system.
It is really true that all numerical calculations in prime base number system can seem to us a little bit unusual, or even hard. In fact, the children in Prime Land learn to add to subtract numbers several years. On the other hand, multiplication and division is very simple.
Recently, somebody has returned from a holiday in the Computer Land where small smart things called computers have been used. It has turned out that they could be used to make addition and subtraction in prime base number system much easier. It has been decided to make an experiment and let a computer to do the operation ``minus one''.
Help people in the Prime Land and write a corresponding program.
For practical reasons we will write here the prime base representation as a sequence of such pi and ei from the prime base representation above for which ei > 0. We will keep decreasing order with regard to pi.
Input
Output
Sample Input
17 1 5 1 2 1 509 1 59 1 0
Sample Output
2 4 3 2 13 1 11 1 7 1 5 1 3 1 2 1
Source
题意有点读不懂啊
简单的分解质因数的题
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
int p[10010];
int e[10010];
int tot;
void factor(long long n)
{
long long temp =(int)sqrt((double)n + 1.0);
for(int i = 2; i <= n; i ++)
{
if(n % i == 0)
{
p[ ++tot] = i;
e[tot] = 0;
while( n % i == 0)
{
e[tot] ++;
n /= i;
}
}
}
if(n != 1)
{
p[++ tot] = n;
e[tot] = 1;
}
}
int quick(int a, int b)
{
int num = 1;
while(b)
{
if(b & 1)
num *= a;
b >>= 1;
a *= a;
}
return num;
}
int main()
{
int a, b;
while(~scanf("%d",&a))
{
if(!a)
break;
scanf("%d", &b);
int num = quick(a, b);
char ch;
while(1)
{
if(getchar() == '\n')
break;
scanf("%d", &a);
scanf("%d", &b);
num *= quick(a, b);
}
tot = 0;
factor(num - 1);
for(int i = tot; i >= 1; i --)
{
if( i == tot)
printf("%d %d", p[i], e[i]);
else
printf(" %d %d", p[i], e[i]);
}
printf("\n");
}
return 0;
}
5万+



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



