#17779: _TLE


rexwu1104@gmail.com (黑雪公主 Black Lotus)


#include <iostream>
#include <cmath>
using namespace std;
bool bang(int kk)
{
  int a=0;
if(kk==1) {
return0;
}
for(int i=1;i<=kk;i++) {
    kk%i==0 ? a+=1 : a=a;
    if (kk%i==0&&i!=1&&i!=kk) {
      return 0;
    }
}
  if (a==2) {
    return 1;
  }
  else {
    return 0;
  }
}
int main()
{
longlongint a, b;
  while (cin >> a >> b) {
    long long int c=a, d=0;
    while (1) {
      if (bang(c)) {
        d+=1; c+=1;
      }
      else {
        c+=1;
      }
      if (c==b+1) {
        break;
      }
    }
    cout << d << endl;
  }
}
請問要如何加速
#17781: Re:TLE


ufve0704 (爬 我爬 我爬爬爬 有排行榜這種東西就是要爬 爬過我上面的那...)


#include
#include
using namespace std;
bool bang(int kk)
{
  int a=0;
if(kk==1) {
return0;
}
for(int i=1;i<=kk;i++) {
    kk%i==0 ? a+=1 : a=a;
    if (kk%i==0&&i!=1&&i!=kk) {
      return 0;
    }
}
  if (a==2) {
    return 1;
  }
  else {
    return 0;
  }
}
int main()
{
longlongint a, b;
  while (cin >> a >> b) {
    long long int c=a, d=0;
    while (1) {
      if (bang(c)) {
        d+=1; c+=1;
      }
      else {
        c+=1;
      }
      if (c==b+1) {
        break;
      }
    }
    cout << d << endl;
  }
}
請問要如何加速

建表


#17784: Re:TLE


rexwu1104@gmail.com (黑雪公主 Black Lotus)


#include
#include
using namespace std;
bool bang(int kk)
{
  int a=0;
if(kk==1) {
return0;
}
for(int i=1;i<=kk;i++) {
    kk%i==0 ? a+=1 : a=a;
    if (kk%i==0&&i!=1&&i!=kk) {
      return 0;
    }
}
  if (a==2) {
    return 1;
  }
  else {
    return 0;
  }
}
int main()
{
longlongint a, b;
  while (cin >> a >> b) {
    long long int c=a, d=0;
    while (1) {
      if (bang(c)) {
        d+=1; c+=1;
      }
      else {
        c+=1;
      }
      if (c==b+1) {
        break;
      }
    }
    cout << d << endl;
  }
}
請問要如何加速

建表


可以說明嗎