#include <cstdio>
#include <iostream>
#define MP 100
using namespace std;
bool ver[300]={false};
int list[1000];
int siever() {
int i, j, k=0;
list[k++]=2;
for (i=3 ; i<=200 ; i+=2)
{
if (ver[i]==false)
{
list[k++]=i;
for (j=3 ; i*j<=200 ; j+=2)
{
ver[i*j]=true;
}
}
}
list[0]=2;
return k;
}
int test(int x, int p)
{
int i, counter=0, temp, rem=1, n=x;
for (i=x ; i>1 ; i--)
{
n=i;
while (n%p == 0)
{
counter++;
n/=p;
}
}
return counter;
}
int main() {
int pl=siever();
int i, n;
while (cin >> n && n)
{
printf("%3d! =",n);
for (i=0 ; i<pl && list[i]<=n ; i++)
{
printf("%3d",test(n,list[i]));
if (i%14 == 0 && i>0 && list[i+1]<=n) printf("\n%6c",' ');
}
printf("\n");
}
return 0;
}
Showing posts with label Output format. Show all posts
Showing posts with label Output format. Show all posts
Wednesday, October 26, 2011
[UVa] 160 - Factors & Factorials
Tuesday, October 25, 2011
[UVa] 392 - Polynomial Showdown
Just conditioning, loads of ifs
If you're getting PE or WA just test with some isolated values for different coefficients. Some of my test cases are.
If you're getting PE or WA just test with some isolated values for different coefficients. Some of my test cases are.
0 0 0 1 22 -333 0 1 -1 0 0 0 0 0 0 -55 5 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -1 0 0 0 0 0 0 0 -1 0 0 0 0 0 0 0 -1 0 0 0 0 0 0 0 -1 0 0 0 0 0 0 0 -1 0 0 0 0 0 0 0 -1 0 0 0 0 0 0 0 -1 0 0 0 0 0 0 0 -1 0 0 0 0 0 0 0 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
x^5 + 22x^4 - 333x^3 + x - 1 -55x^2 + 5x 0 -1 -x -x^2 -x^3 -x^4 -x^5 -x^6 -x^7 -x^8 0
#include <stdio.h>
#include <string.h>
int a[10];
int main()
{
int i, print, z;
//freopen("input.txt","r+",stdin);
//freopen("output.txt","w+",stdout);
while (scanf("%d %d %d %d %d %d %d %d %d",&a[8],&a[7],&a[6],&a[5],&a[4],&a[3],&a[2],&a[1],&a[0])==9)
{
for (i=0, z=1 ; i<9 && z; i++) //-----|Checking if the
if (a[i]) z=0; //-----|polynomial is zero
if (z) { //-----|The polynomial is found
printf("0\n"); //-----|to be zero in fact
continue;
}
//-[ The first value of the equation is not printed yet ]
print=0;
for (i=8 ; i>1 ; i--)
{
if (print && a[i]) printf(" ");
if (a[i]==-1)
{
(print? printf("- x^%d",i) : printf("-x^%d",i) );
} else if (a[i]==1)
{
(print? printf("+ x^%d",i) : printf("x^%d",i) );
} else if (a[i]<0)
{
(print? printf("- %dx^%d",-1*a[i],i) : printf("%dx^%d",a[i],i) );
} else if (a[i])
{
(print? printf("+ %dx^%d",a[i],i) : printf("%dx^%d",a[i],i) );
}
//-- [ From the next time a space will seperate characters ]
if(a[i]) print=1;
}
if (a[i])
{
if (print && a[i]) printf(" ");
if (a[i]==-1)
{
(print? printf("- x") : printf("-x") );
} else if (a[i]==1)
{
(print? printf("+ x") : printf("x") );
} else if (a[i]<0)
{
(print? printf("- %dx",-1*a[i]) : printf("%dx",a[i]) );
} else if (a[i])
{
(print? printf("+ %dx",a[i]) : printf("%dx",a[i]));
}
//-- [ From the next time a space will seperate characters ]
if(a[i]) print=1;
}
i--;
if (a[i])
{
if (print && a[i]) printf(" ");
if (a[i]<0)
{
(print ? printf("- %d",-1*a[i]) : printf("%d",a[i]) );
} else if (a[i])
{
(print ? printf("+ %d",a[i]) : printf("%d",a[i]) );
}
}
printf("\n");
}
return 0;
}
Subscribe to:
Posts (Atom)
Connect Rapoo MT750S with Linux (Tested on Manjaro)
I bought this obvious copy of MX Master 2S in hopes of having the device switching functionality along with a lightweight body because I ha...
-
I like coding a lot, keeps me glued to the PC for hours. For that reason it's a need to edit the Syntax Highlighter to suit my eyes for...
-
Method: The problem at first glance seems too straightforward but it's not that much. Think a bit about the lines "Erin can add ...
-
I've been constantly switching between my two OSs, Win7 and Linux Mint for just flashing a ROM to my Xperia device. And ofcourse, I hat...