2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

(ベンチマーク)STM8Sで素数を求める3...100まで(理系フリマ入手)

Last updated at Posted at 2024-08-16

x 理系フリマ831にあるよ

x いちおう、c++じゃないけど、めんどくさいので

目的
素数を求めて時間を測って遊ぶ
2から開始しする
割るのは、2からn-1まで割る
ちゃんと割ってあまりを求める
z = x / y
a = x - ( z * y )

いろいろ
Arduino UNOより速い
ハードウェア、乗算器と除算器があるため

結果

o_coq323.jpg

o_coq324.jpg

o_coq325.jpg

o_coq326.jpg

プログラム



//sosuu_STM8S_1

//インクルド
#include <Arduino.h>
#include "Serial.h"


void setup() {

  Serial_begin(9600);

}//setup

void loop() {

  int s[100];
  for (int ii = 0; ii < 100; ii++) {
    s[ii] = 0;
  }//for

  int time;

  int a=1;//work

  int pp = 0;
  //s[pp++] = 1;//debug
  //s[pp++] = 2;//debug
  Serial_println_s("START>>");
  time = millis();

  int ii;int jj;
  for (ii = 2; ii < (100 + 1); ii++) {

    //Serial.print('(');  //debug
    //Serial.print(ii);   //debug
    //Serial.print(')');  //debug
    //Serial.println();   //debug

    for (jj = 2; jj < (ii); jj++) {

      //Serial.print('['); //debug
      //Serial.print(jj);  //debug
      //Serial.print(']'); //debug

      a = ii / jj;
      a = ii - (a * jj);
      if ( a == 0) {
        //Serial.print('*');//debug
        break;
      }//if

    }//for
    if (a != 0) {
      //Serial.print('@');
      s[pp++] = ii;
    }
    //Serial.println();//debug
  }//for

  time = millis() - time;
  Serial_print_s("millis=");
  Serial_println_i(time);

  int yy = 0;
  while (s[yy] != 0) {
    Serial_print_i(s[yy]);
    Serial_print_c(',');
    yy++;
  }//while
  Serial_println_s("");

  Serial_println_s("<<END");
  delay(3000);
  //while (1) {} //debug
}//loop



2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?