AUCTION.cpp [ OLP chuyên tin Năm 2010 ]

 Tất cả chỉ là tham khảo thôi nhé.

# include<math.h>
# include<stdio.h>
# define vao"AUCTION.INP"
# define ra"AUCTION.OUT"
int main(){
    FILE *f1,*f2;
    long A,B,i,j;
    int demso=0,dem,luu[6],kt,tam;
    f1=fopen( vao ,"r");
        fscanf(f1,"%d%d",&A,&B);
    fclose(f1);
    f2=fopen( ra ,"w");
    for(i=A; i<=B; i++){
             kt=1;
             for(j=2; j<i; j++)
                if(i%j==0){
                    kt=0;
                    break;
                 }
            if(kt){
                    dem=0;    tam=i;
                    while(tam>9){
                        luu[dem]=tam%10;
                        dem=dem+1;
                        tam=tam/10;
                     }
                    luu[dem] = tam;
                    for(j=0;j<=dem/2;j++)
                        if(luu[j]!=luu[dem-j]){
                             kt=0;
                             break;
                        }
            }
             if(kt)        demso=demso+1;            
    }
    fprintf(f2,"so luong: %d",demso);
    fclose(f2);
    return 0;
}
Ntech Developers

Programs must be written for people to read, and only incidentally for machines to execute.

Post a Comment

Previous Post Next Post