Pages

Tuesday 13 November 2012

UVA - 10006 - Carmichael Numbers

#include <stdio.h>

int main()
{   int x,flag,i;
    int arr[]={561, 1105, 1729, 2465, 2821,
     6601, 8911, 10585, 15841, 29341,
      41041, 46657, 52633, 62745, 63973};
    while(1){
        flag=0;
        scanf("%d",&x);
        if(x==0)
            break;
        for(i=0;i<15;i++){
            if(x==arr[i]){
                flag=1;
                break;
            }
        }
        if(flag)
            printf("The number %d is a Carmichael number.\n",x);
        else
            printf("%d is normal.\n",x);
    }

       return 0;
}

4 comments:

  1. The problem objective is to get the numbers carmichael not enter them directly as you do.

    ReplyDelete
    Replies
    1. Thanks a lot for your comment :) ... Actually i got these numbers by another program I wrote ...
      This actually for the time complexity issue ... You just have only several cases .. Why don't we store only the required elements to get the best time ;) ??

      Delete
    2. From my point of view I think it's more important to solve a problem correctly. In a real programming competition I think is not allowed to use this type of "shortcuts".

      This is just my opinion ;-)

      Delete
    3. Thanks a lot for your reply :) :D I really apperciate your opinion ... I will try to find the code I generated this number with to add it ...

      Delete