diff --git a/isprime-python/app.py b/isprime-python/app.py index de64bd6..51672d3 100644 --- a/isprime-python/app.py +++ b/isprime-python/app.py @@ -5,9 +5,19 @@ from flask import Flask app = Flask(__name__) @app.route('/') -def hello_world(): - target = os.environ.get('TARGET', 'World') - return 'Hello {}!\n'.format(target) +def isprime(): + n = os.environ.get('TARGET', '42069') + if n == 2 or n == 3: return "Prime" + if n < 2 or n%2 == 0: return "Not Prime" + if n < 9: return "Prime" + if n%3 == 0: return "Not Prime" + r = int(n**0.5) + f = 5 + while f <= r: + if n%f == 0: return "Not Prime" + if n%(f+2) == 0: return "Not Prime" + f +=6 + return "Prime" if __name__ == "__main__": - app.run(debug=True,host='0.0.0.0',port=int(os.environ.get('PORT', 8080))) + app.run(debug=True,host='0.0.0.0',port=int(os.environ.get('PORT', 8080)))