[shkola] Interesting ... non-running task
- From: Lyudmil Antonov <lyudmil@xxxxxxx>
- To: shkola@xxxxxxxxxxxxx
- Date: Mon, 24 Mar 2003 14:26:00 -0500
Hora, eto vi edna interesna, zadacha.. btw prastam vi i reshenieto da
gorazgledate.. Mnogo stranno zastoto acm-a mi dava TLE na taia .. a
vremeto e 10 sec. Ne moga da ia optimiziram poveche . Ivo niakakvi idei
. Nomera na zadachata e 10299. tova koeto triabva da se napravi e
lsednoto . Dava se edno chislo N i triabva da se nameriat vsicki po
malki ot nego koito sa vzaimno prosti s nego ... toest da kazem 12 i 7
.. niamat obsti deliteli , sledovatelno sa vzaimno prosti. Eto vi i
src-to :
#include <stdio.h>
#define lint long long
lint round ( double num) {
lint inum = num;
if ( num > inum )
return num + 1;
else
return num;
}
lint solve(lint number) {
double numdif = number-1;
lint breaked = 1;
lint savednum = number;
lint i;
while (breaked) {
breaked = 0;
for (i=2; i<=sqrt(number);i++)
if ( number % i == 0) {
numdif = (double) numdif/i*(i-1);
while (number % i == 0)
number/=i;
breaked = 1;
break;
}
}
if ((!breaked)&&(number>1))
if ( savednum != number)
numdif= (double) numdif/number*(number-1);
return round(numdif);
}
int main() {
lint rnum,nums;
scanf("%Li",&rnum);
while (rnum != 0) {
if (rnum != 1)
nums = solve(rnum);
else
nums = 0;
printf("%Li\n",nums);
if (scanf("%Li\n",&rnum) != 1)
break;
}
return 0;
}
- Follow-Ups:
- [shkola] Re: Interesting ... non-running task
- From: Ivaylo Riskov
- [shkola] Re: Interesting ... non-running task
- From: Rangel Dokov
Other related posts:
- » [shkola] Interesting ... non-running task
- » [shkola] Re: Interesting ... non-running task
- » [shkola] Re: Interesting ... non-running task
- » [shkola] Re: Interesting ... non-running task
- » [shkola] Re: Interesting ... non-running task
- » [shkola] Re: Interesting ... non-running task
- » [shkola] Re: Interesting ... non-running task
- » [shkola] Re: Interesting ... non-running task
- » [shkola] Re: Interesting ... non-running task
- » [shkola] Re: Interesting ... non-running task
- » [shkola] Re: Interesting ... non-running task
- » [shkola] Re: Interesting ... non-running task
- » [shkola] Re: Interesting ... non-running task
- [shkola] Re: Interesting ... non-running task
- From: Ivaylo Riskov
- [shkola] Re: Interesting ... non-running task
- From: Rangel Dokov