zoukankan      html  css  js  c++  java
  • 【ACM】hdu_zs2_1005_Problem E _201308030747

    Problem E
    Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other)
    Total Submission(s) : 83   Accepted Submission(s) : 19
    Font: Times New Roman | Verdana | Georgia
    Font Size: ← →
    Problem Description
    对于表达式n^2+n+41,当n在(x,y)范围内取整数值时(包括x,y)(-39<=x<y<=50),判定该表达式的值是否都为素数。
    Input
    输入数据有多组,每组占一行,由两个整数x,y组成,当x=0,y=0时,表示输入结束,该行不做处理。
    Output
    对于每个给定范围内的取值,如果表达式的值都为素数,则输出"OK",否则请输出“Sorry”,每组输出占一行。

    Sample Input
    0 1
    0 0
    Sample Output
    OK


    #include <stdio.h>
    //#include <math.h>
    int ss(int n)
    {
     int i;
     if(n>1){
     if(n==2)
     return 1;
     else
     {
      //n=(int)sqrt(n);
      for(i=2;i<n;i++)
      if(n%i==0)
      {
      return 0;
      break;
      }
      if(i>=n)
      return 1;
     }
     }
     else
     return 0;
    }  
    int main()
    {
     int n,m;
     while(scanf("%d %d",&n,&m),n||m)
     {
      int i,j,k,t;
      if(n>m)
      {k=n;n=m;m=k;}
      for(i=n;i<=m;i++)
      {
       t=i*i+i+41;
       //printf("%d ",t);
       j=ss(t);
       if(j==0)
       {
        printf("Sorry ");
        break;
       }
      }
      if(i>m)
      printf("OK ");
     }
     return 0;
    }

  • 相关阅读:
    Nginx + uWSGI 配置django
    django视图缓存的实现
    scrapy 资料
    scrapy 安装
    程序题做题一般步骤
    检查代码的一般步骤
    Mathematical-Analysis-I-4
    Mathematical-Analysis-I-3
    Mathematical-Analysis-I-1
    Mathematical-Analysis-I-2
  • 原文地址:https://www.cnblogs.com/xl1027515989/p/3239337.html
Copyright © 2011-2022 走看看