zoukankan      html  css  js  c++  java
  • 判断素数问题201308031030.txt

    Problem E
    Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other)
    Total Submission(s) : 148   Accepted Submission(s) : 38
    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>
    int sushu(int n)
    {
     int i;
     if(n>1){
     if(n==2)
     return 1;
     else
     {
      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;
       j=sushu(t);
       if(j==0)
       {
        printf("Sorry ");
        break;
       }
      }
      if(i>m)
      printf("OK ");
     }
     return 0;
    }

  • 相关阅读:
    Mysql 库表
    Mysql (二)
    SQLAlchemy
    Mysql 测试题
    jquery
    抽屉 演示
    前端项目
    JavaScript
    Html Css  练习
    Pandas之DataFrame——Part 3
  • 原文地址:https://www.cnblogs.com/xiaziteng/p/sushu.html
Copyright © 2011-2022 走看看