ssuk's story 2009. 6. 3. 11:21
반응형

I hate the people who only believe what they think.

They don't liesten that other people think or know even if it is obvoius certain.

Those people always think they are always correct and other people are wrong.

When I talk to them, it makes me mad and uncomfortable.
 
Why do they act like that?

I don't understand.

Every people can be wrong. 

If they realize that they are wrong, they should liesten others thinking and the fact.

I don't want to talk to them anymore.

반응형

'ssuk's story' 카테고리의 다른 글

공부하기 좋은 사이트  (0) 2009.09.16
Why do I have a blackout?  (0) 2009.06.03
ssuk's first story  (1) 2009.06.02
posted by ssuk1010
:
ACM 2009. 6. 2. 21:11
반응형

There are two kinds of ways that I solve.
But both are not accepted from Judge Server because of Time Limit.

----------------------------------------------------------------------------------------------

#include <stdio.h>
#include <string.h>
#include <math.h>

#define MAX_NUM 65001
#define MIN_NUM 2

int carmichaelTable[MAX_NUM];

void precalculate(void);
int isCarMichaelFuc(int number);
unsigned long long myPow(int first, int second);

int main(void)
{
   
int i, inputNumber, isCarmichael;
   
long long result;

   
memset(carmichaelTable, 0, sizeof(carmichaelTable));

   
precalculate();

   
while(scanf("%d", &inputNumber) && inputNumber!=0)
   
{
       
if( !carmichaelTable[inputNumber] )
       
{
           
printf("%d is normal.\n", inputNumber);
       
}
       
else
       
{
           
printf("The number %d is a Carmichael number.\n", inputNumber);
       
}
   
}
   
return 0;
}

void precalculate(void)
{
   
int i, isCarmichael;
   
for(i=MIN_NUM; i<MAX_NUM; i++)
   
{
       
isCarmichael = 1;
       
isCarmichael = isCarMichaelFuc(i);
       
//printf("%d isCarmichael = %d\n", j, isCarmichael);
       
if( isCarmichael ) {
           
carmichaelTable[i] = 1;
           
//printf("%d is %d\n", i, carmichaelTable[i]);
       
}
   
}
}

int isCarMichaelFuc(int number)
{
   
int i, isCarmichael=1;
   
unsigned long long result;
   
for(i=MIN_NUM; i<number; i++)
   
{
       
result = myPow(i, number);
       
//printf("%d %d = %d\n", i, number, result);
       
if( result != i) {
           
isCarmichael = 0;
           
break;
       
}
   
}
   
return isCarmichael;
}

unsigned long long myPow(int first, int second)
{
   
int i;
   
unsigned long long result = first;
   
for(i=1; i<second; i++)
   
{
       
result *= first;
       
result %= second;
   
}
   
//printf("result = %llu\n", result);
   
return result;
}

 
 ----------------------------------------------------------------------------------------------
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include <stdio.h>
#include <string.h>
#include <math.h>
 
#define MAX_NUM 65001 
#define MIN_NUM 2 
 
int isCarMichaelFuc(int number);
unsigned long long myPow(int first, int second);
 
int main(void)
{
    int i, inputNumber, isPrime, isCarmichael;
    long long result;
 
    while(scanf("%d", &inputNumber) && inputNumber!=0)
    {
        isPrime = 1;
        for(i=MIN_NUM; i<inputNumber; i++)
        {
            if( inputNumber%i == 0 )
            {
                isPrime = 0;
                break;
            }
        }
        if( !isPrime )
        {
            isCarmichael = isCarMichaelFuc(inputNumber);
            if( !isCarmichael )
            {
                printf("%d is normal.\n", inputNumber);
            }
            else
            {
                printf("The number %d is a Carmichael number.\n", inputNumber);
            }
        }
        else
            printf("%d is normal.\n", inputNumber);
    }
    return 0;
}
 
int isCarMichaelFuc(int number)
{
    int i, isCarmichael=1;
    unsigned long long result;
    for(i=MIN_NUM; i<number; i++)
    {
        result = myPow(i, number);
        if( result != i) {
            isCarmichael = 0;
            break;
        }
    }
    return isCarmichael;
}
 
unsigned long long myPow(int first, int second)
{
    int i;
    unsigned long long result = first;
    for(i=1; i<second; i++)
    {
        result *= first;
        result %= second;
    }
    return result;
}
반응형

'ACM' 카테고리의 다른 글

[Accept] 10018 Reverse and Add  (0) 2009.06.08
[10018] Reverse and Add  (0) 2009.06.03
[Accept] 10006 Carmichael Numbers  (0) 2009.06.02
[Accept] 10110 Light, more light  (0) 2009.06.02
[Accept] 850 Crypt Kicker II  (0) 2009.06.02
posted by ssuk1010
:
ACM 2009. 6. 2. 21:08
반응형
I got accept from Judge Server.
But I don't like my code.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include <stdio.h>
#include <string.h>
 
int main(void)
{
    int i, inputNumber, isCarmichael;
    long long result;
    int table[15]={561,1105,1729,2465,2821,6601,8911,10585,15841,29341,41041,46657,52633,62745,63973};
 
    while(scanf("%d", &inputNumber) && inputNumber!=0)
    {
        isCarmichael = 0;
        for(i=0; i<15; i++)
        {
            if( table[i] == inputNumber )
            {
                isCarmichael = 1;
            }
        }
        if( isCarmichael )
            printf("The number %d is a Carmichael number.\n", inputNumber);
        else
            printf("%d is normal.\n", inputNumber);
    }
 
    return 0;
}
반응형

'ACM' 카테고리의 다른 글

[10018] Reverse and Add  (0) 2009.06.03
[Time Limit] Carmichael Numbers  (0) 2009.06.02
[Accept] 10110 Light, more light  (0) 2009.06.02
[Accept] 850 Crypt Kicker II  (0) 2009.06.02
[Accept] 10132 File Fragmentation  (0) 2009.06.02
posted by ssuk1010
: