Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Challenges

Post History

71%
+3 −0
Challenges Determine whether an integer is square-free

Python3, 39 bytes lambda n:all(n%i**2for i in range(2,n)) Try it online! Makes a list comprehension from the numbers 2 through n of the remainder of the square, and then checks whether the lis...

posted 3y ago by dino‭  ·  edited 3y ago by dino‭

Answer
#12: Post edited by user avatar dino‭ · 2022-01-06T14:17:03Z (almost 3 years ago)
  • # [Python3](https://www.python.org/), 44 bytes
  • ```python
  • lambda n:all(n%i**2for i in range(2,n))
  • ```
  • [Try it online!](https://tio.run/##PYxBCsIwFET3PcVQkCSlC02DSqFXcC8qEjGxgfS3NHEhpWePLYgDw7zNvOET256qZNFck9fd46lBtfae08YVhbT9CAdHGDW9DJclCZGiCfFO7y6gwWW3LSFVCSWXqpX3lTr89njLVgOthv@rzrBkGB1FbvOJ5hoTO5vA4CwsJwHjgwE79WzORfoC "Python 3 – Try It Online")
  • Makes a list comprehension from the numbers `2` through `n` of the remainder of the square, and then checks whether the list contains `0`
  • -8 bytes thanks to [celtschk‭](https://codegolf.codidact.com/users/8056)
  • -5 bytes thanks to [Moshi](https://codegolf.codidact.com/users/53196)
  • # [Python3](https://www.python.org/), 39 bytes
  • ```python
  • lambda n:all(n%i**2for i in range(2,n))
  • ```
  • [Try it online!](https://tio.run/##PYxBCsIwFET3PcVQkCSlC02DSqFXcC8qEjGxgfS3NHEhpWePLYgDw7zNvOET256qZNFck9fd46lBtfae08YVhbT9CAdHGDW9DJclCZGiCfFO7y6gwWW3LSFVCSWXqpX3lTr89njLVgOthv@rzrBkGB1FbvOJ5hoTO5vA4CwsJwHjgwE79WzORfoC "Python 3 – Try It Online")
  • Makes a list comprehension from the numbers `2` through `n` of the remainder of the square, and then checks whether the list contains `0`
  • -8 bytes thanks to [celtschk‭](https://codegolf.codidact.com/users/8056)
  • -5 bytes thanks to [Moshi](https://codegolf.codidact.com/users/53196)
#11: Post edited by user avatar dino‭ · 2022-01-06T14:16:22Z (almost 3 years ago)
Implement suggested changes from Moshi
  • # [Python3](https://www.python.org/), 44 bytes
  • ```python
  • lambda n:not 0in[n%i**2 for i in range(2,n)]
  • ```
  • [Try it online!](https://tio.run/##PYzRCoIwGIXvfYqDEFPxwuaoEHyF7sMkFm010H@yrYsQn30pRAcO57s53/QJL0t11GivcZDj/SFBDdmAylBHO1MUHNo6GBiCk/RUGS8p72NQPtzoPXq06PZVCS5KCL5WbHyoxfG3pz7ZDLQZ/q8mwZrJGQqZTmdaGszsojyD0dAZ5VCDV2Bny5Y0j18 "Python 3 – Try It Online")
  • Makes a list comprehension from the numbers `2` through `n` of the remainder of the square, and then checks whether the list contains `0`
  • -8 bytes thanks to [celtschk‭](https://codegolf.codidact.com/users/8056)
  • # [Python3](https://www.python.org/), 44 bytes
  • ```python
  • lambda n:all(n%i**2for i in range(2,n))
  • ```
  • [Try it online!](https://tio.run/##PYxBCsIwFET3PcVQkCSlC02DSqFXcC8qEjGxgfS3NHEhpWePLYgDw7zNvOET256qZNFck9fd46lBtfae08YVhbT9CAdHGDW9DJclCZGiCfFO7y6gwWW3LSFVCSWXqpX3lTr89njLVgOthv@rzrBkGB1FbvOJ5hoTO5vA4CwsJwHjgwE79WzORfoC "Python 3 – Try It Online")
  • Makes a list comprehension from the numbers `2` through `n` of the remainder of the square, and then checks whether the list contains `0`
  • -8 bytes thanks to [celtschk‭](https://codegolf.codidact.com/users/8056)
  • -5 bytes thanks to [Moshi](https://codegolf.codidact.com/users/53196)
#10: Post edited by user avatar dino‭ · 2022-01-05T22:06:45Z (almost 3 years ago)
  • # [Python3](https://www.python.org/), 45 bytes
  • ```python
  • lambda n:not 0in[n%(i*i) for i in range(2,n)]
  • ```
  • [Try it online!](https://tio.run/##PYzBCoJAGITvPsUQxO6GB9OlQvAVuodJGO3WD/qvuNshxGffFKKBYb7LfMMnvBwX0aK6xq7t748WXLILyIhr3krakYJ1IwjEGFt@GpmnrJoYjA83fvceFep9liLXKXS@VK98KPTxt6cmWQ28Gv6vMsGSYSQO0m4mnktM4mK8AFlYyQqm8wbi7MS8UfEL "Python 3 – Try It Online")
  • Makes a list comprehension from the numbers `2` through `n` of the remainder of the square, and then checks whether the list contains `0`
  • -8 bytes thanks to [celtschk‭](https://codegolf.codidact.com/users/8056)
  • # [Python3](https://www.python.org/), 44 bytes
  • ```python
  • lambda n:not 0in[n%i**2 for i in range(2,n)]
  • ```
  • [Try it online!](https://tio.run/##PYzRCoIwGIXvfYqDEFPxwuaoEHyF7sMkFm010H@yrYsQn30pRAcO57s53/QJL0t11GivcZDj/SFBDdmAylBHO1MUHNo6GBiCk/RUGS8p72NQPtzoPXq06PZVCS5KCL5WbHyoxfG3pz7ZDLQZ/q8mwZrJGQqZTmdaGszsojyD0dAZ5VCDV2Bny5Y0j18 "Python 3 – Try It Online")
  • Makes a list comprehension from the numbers `2` through `n` of the remainder of the square, and then checks whether the list contains `0`
  • -8 bytes thanks to [celtschk‭](https://codegolf.codidact.com/users/8056)
#9: Post edited by user avatar dino‭ · 2022-01-05T21:48:57Z (almost 3 years ago)
Implement suggested changes from celtschk
  • # [Python3](https://www.python.org/), 53 bytes
  • ```python
  • lambda n:not 1in[n%i==0==(n/i)%i for i in range(2,n)]
  • ```
  • [Try it online!](https://tio.run/##PYxNCsIwGET3PcUglCRQsD9BpZAruJdapGKigfZLaeJCSs8eWxAHhnmbeeMnvBxV0UBdY98N90cHqskFFJYaSq1SuVKc9lakFsZNsLCEqaOn5mVGoo1B@3Cj9@Ch0BR5hlJmkOVaufGhksffntpkM9Bm@L/qBGvGyVLgZjfTUmNmF@0ZrIHhJKB7r8HOji07Eb8 "Python 3 – Try It Online")
  • Makes a list comprehension of numbers from `2` to `n` of whether they factor into `n` twice, and then checks whether the list contains `True`
  • # [Python3](https://www.python.org/), 45 bytes
  • ```python
  • lambda n:not 0in[n%(i*i) for i in range(2,n)]
  • ```
  • [Try it online!](https://tio.run/##PYzBCoJAGITvPsUQxO6GB9OlQvAVuodJGO3WD/qvuNshxGffFKKBYb7LfMMnvBwX0aK6xq7t748WXLILyIhr3krakYJ1IwjEGFt@GpmnrJoYjA83fvceFep9liLXKXS@VK98KPTxt6cmWQ28Gv6vMsGSYSQO0m4mnktM4mK8AFlYyQqm8wbi7MS8UfEL "Python 3 – Try It Online")
  • Makes a list comprehension from the numbers `2` through `n` of the remainder of the square, and then checks whether the list contains `0`
  • -8 bytes thanks to [celtschk‭](https://codegolf.codidact.com/users/8056)
#8: Post edited by user avatar dino‭ · 2022-01-05T17:22:09Z (almost 3 years ago)
  • # [Python3](https://www.python.org/), 53 bytes
  • ```python
  • lambda n:not 1in[n%i==0==(n/i)%i for i in range(2,n)]
  • ```
  • [Try it online!](https://tio.run/##PYtBCoMwFAX3nuIhiAkIVetKyBW6L1aKpUn9YH5ski6KeHarmw7Mbmb@xtHxeTPeWdghjiA7Ox8R3j4mBuq2TYN9PAdwyy6iIu44I6VKpQSfSGYE4zwIxPADv7SoC5b9FnWId/7YAIWuKgvUTYGm3m365Dj4OP5Vm2Bn9sRRmHThtcWSX3XIQQZGsISegkZ@cfmayu0H "Python 3 – Try It Online")
  • Makes a list comprehension of numbers from `2` to `n` of whether they factor into `n` twice, and then checks whether the list contains `True`
  • # [Python3](https://www.python.org/), 53 bytes
  • ```python
  • lambda n:not 1in[n%i==0==(n/i)%i for i in range(2,n)]
  • ```
  • [Try it online!](https://tio.run/##PYxNCsIwGET3PcUglCRQsD9BpZAruJdapGKigfZLaeJCSs8eWxAHhnmbeeMnvBxV0UBdY98N90cHqskFFJYaSq1SuVKc9lakFsZNsLCEqaOn5mVGoo1B@3Cj9@Ch0BR5hlJmkOVaufGhksffntpkM9Bm@L/qBGvGyVLgZjfTUmNmF@0ZrIHhJKB7r8HOji07Eb8 "Python 3 – Try It Online")
  • Makes a list comprehension of numbers from `2` to `n` of whether they factor into `n` twice, and then checks whether the list contains `True`
#7: Post edited by user avatar dino‭ · 2022-01-05T17:20:18Z (almost 3 years ago)
  • # [Python3](https://www.python.org/), 53 bytes
  • ```python
  • lambda n:not 1in[n%i==0==(n/i)%i for i in range(2,n)]
  • ```
  • [Try it online!](https://tio.run/##PYtBCoMwFAX3nuIhiAkIVetKyBW6L1aKpUn9YH5ski6KeHarmw7Mbmb@xtHxeTPeWdghjiA7Ox8R3j4mBuq2TYN9PAdwyy6iIu44I6VKpQSfSGYE4zwIxPADv7SoC5b9FnWId/7YAIWuKgvUTYGm3m365Dj4OP5Vm2Bn9sRRmHThtcWSX3XIQQZGsISegkZ@cfmayu0H "Python 3 – Try It Online")
  • Makes a list comprehension of numbers from `2` to `n` of whether they factor into `n` twice, and then checks whether the list contains `True`
  • ## Longer (more readable?) version (102 bytes)
  • ```python
  • def f(n):
  • for i in range(2,int(sqrt(n)+1)):
  • n=(n/i if n%i==0 else n)
  • if n%i==0:return 0
  • return 1
  • ```
  • [Try it online!](https://tio.run/##PY5BCsIwFET3PcUgSBIs2NauCrmCexGRgokN2J@apAspPXtMULr4MPx58Gb6hMHSKWpnR4x9GGDGyboA/3YhPpSG5iS6Ato6GBiC6@mpeFMaCjxDqT7UIiMgyemYIA3aGykrqJdXIJGq7dc5FWZHqAr8Ux2D8uFO8@ghca2rEk1bom3StbciiymLNyqrgMnlBXq30NphYRflWbbkuT8vO1u27kT8Ag "Python 3 – Try It Online")
  • Loops through 2 - the square root of the input number (rounded up) as `i`, and return `False` if `i` factors into the input number twice. If no instance of `i` factors twice into the input number then return `True`.
  • # [Python3](https://www.python.org/), 53 bytes
  • ```python
  • lambda n:not 1in[n%i==0==(n/i)%i for i in range(2,n)]
  • ```
  • [Try it online!](https://tio.run/##PYtBCoMwFAX3nuIhiAkIVetKyBW6L1aKpUn9YH5ski6KeHarmw7Mbmb@xtHxeTPeWdghjiA7Ox8R3j4mBuq2TYN9PAdwyy6iIu44I6VKpQSfSGYE4zwIxPADv7SoC5b9FnWId/7YAIWuKgvUTYGm3m365Dj4OP5Vm2Bn9sRRmHThtcWSX3XIQQZGsISegkZ@cfmayu0H "Python 3 – Try It Online")
  • Makes a list comprehension of numbers from `2` to `n` of whether they factor into `n` twice, and then checks whether the list contains `True`
#6: Post edited by user avatar dino‭ · 2022-01-05T17:19:59Z (almost 3 years ago)
  • # [Python3](https://www.python.org/), 53 bytes
  • ```python
  • lambda n:not 1in[n%i==0==(n/i)%i for i in range(2,n)]
  • ```
  • [Try it online!](https://tio.run/##PYtBCoMwFAX3nuIhiAkIVetKyBW6L1aKpUn9YH5ski6KeHarmw7Mbmb@xtHxeTPeWdghjiA7Ox8R3j4mBuq2TYN9PAdwyy6iIu44I6VKpQSfSGYE4zwIxPADv7SoC5b9FnWId/7YAIWuKgvUTYGm3m365Dj4OP5Vm2Bn9sRRmHThtcWSX3XIQQZGsISegkZ@cfmayu0H "Python 3 – Try It Online")
  • Makes a list comprehension of numbers from `2` to `n` of whether they factor into `n` twice, and then checks whether the list contains `True`
  • ## More friendly version (102 bytes)
  • ```python
  • def f(n):
  • for i in range(2,int(sqrt(n)+1)):
  • n=(n/i if n%i==0 else n)
  • if n%i==0:return 0
  • return 1
  • ```
  • [Try it online!](https://tio.run/##PY5BCsIwFET3PcUgSBIs2NauCrmCexGRgokN2J@apAspPXtMULr4MPx58Gb6hMHSKWpnR4x9GGDGyboA/3YhPpSG5iS6Ato6GBiC6@mpeFMaCjxDqT7UIiMgyemYIA3aGykrqJdXIJGq7dc5FWZHqAr8Ux2D8uFO8@ghca2rEk1bom3StbciiymLNyqrgMnlBXq30NphYRflWbbkuT8vO1u27kT8Ag "Python 3 – Try It Online")
  • Loops through 2 - the square root of the input number (rounded up) as `i`, and return `False` if `i` factors into the input number twice. If no instance of `i` factors twice into the input number then return `True`.
  • # [Python3](https://www.python.org/), 53 bytes
  • ```python
  • lambda n:not 1in[n%i==0==(n/i)%i for i in range(2,n)]
  • ```
  • [Try it online!](https://tio.run/##PYtBCoMwFAX3nuIhiAkIVetKyBW6L1aKpUn9YH5ski6KeHarmw7Mbmb@xtHxeTPeWdghjiA7Ox8R3j4mBuq2TYN9PAdwyy6iIu44I6VKpQSfSGYE4zwIxPADv7SoC5b9FnWId/7YAIWuKgvUTYGm3m365Dj4OP5Vm2Bn9sRRmHThtcWSX3XIQQZGsISegkZ@cfmayu0H "Python 3 – Try It Online")
  • Makes a list comprehension of numbers from `2` to `n` of whether they factor into `n` twice, and then checks whether the list contains `True`
  • ## Longer (more readable?) version (102 bytes)
  • ```python
  • def f(n):
  • for i in range(2,int(sqrt(n)+1)):
  • n=(n/i if n%i==0 else n)
  • if n%i==0:return 0
  • return 1
  • ```
  • [Try it online!](https://tio.run/##PY5BCsIwFET3PcUgSBIs2NauCrmCexGRgokN2J@apAspPXtMULr4MPx58Gb6hMHSKWpnR4x9GGDGyboA/3YhPpSG5iS6Ato6GBiC6@mpeFMaCjxDqT7UIiMgyemYIA3aGykrqJdXIJGq7dc5FWZHqAr8Ux2D8uFO8@ghca2rEk1bom3StbciiymLNyqrgMnlBXq30NphYRflWbbkuT8vO1u27kT8Ag "Python 3 – Try It Online")
  • Loops through 2 - the square root of the input number (rounded up) as `i`, and return `False` if `i` factors into the input number twice. If no instance of `i` factors twice into the input number then return `True`.
#5: Post edited by user avatar dino‭ · 2022-01-05T17:14:22Z (almost 3 years ago)
  • # [Python3](https://www.python.org/), 53 bytes
  • ```python
  • lambda n:not 1in[n%i==0==(n/i)%i for i in range(2,n)]
  • ```
  • [Try it online!](https://tio.run/##PYvBCsIwGIPve4ogSFsY6OZOg72Cd5lDKmtdYf0723qQsWev68VASAL5lm@cHF2S9s7CyjjB2MX5iPD2sdDo7mmW9jlKUEsuojLU56SjgaQRuXM6GbFv7TwMDMFLeilelySGFFWID/rYgA59dS5RNyWaenczFJmgTPxfbYFdizcUuT6stLVY2U0FBqOhOQmoOSiwq2PbQaQf "Python 3 – Try It Online")
  • Makes a list comprehension of numbers from `2` to `n` of whether they factor into `n` twice, and then checks whether the list contains `True`
  • ## More friendly version (102 bytes)
  • ```python
  • def f(n):
  • for i in range(2,int(sqrt(n)+1)):
  • n=(n/i if n%i==0 else n)
  • if n%i==0:return 0
  • return 1
  • ```
  • [Try it online!](https://tio.run/##PY5BCsIwFET3PcUgSBIs2NauCrmCexGRgokN2J@apAspPXtMULr4MPx58Gb6hMHSKWpnR4x9GGDGyboA/3YhPpSG5iS6Ato6GBiC6@mpeFMaCjxDqT7UIiMgyemYIA3aGykrqJdXIJGq7dc5FWZHqAr8Ux2D8uFO8@ghca2rEk1bom3StbciiymLNyqrgMnlBXq30NphYRflWbbkuT8vO1u27kT8Ag "Python 3 – Try It Online")
  • Loops through 2 - the square root of the input number (rounded up) as `i`, and return `False` if `i` factors into the input number twice. If no instance of `i` factors twice into the input number then return `True`.
  • # [Python3](https://www.python.org/), 53 bytes
  • ```python
  • lambda n:not 1in[n%i==0==(n/i)%i for i in range(2,n)]
  • ```
  • [Try it online!](https://tio.run/##PYtBCoMwFAX3nuIhiAkIVetKyBW6L1aKpUn9YH5ski6KeHarmw7Mbmb@xtHxeTPeWdghjiA7Ox8R3j4mBuq2TYN9PAdwyy6iIu44I6VKpQSfSGYE4zwIxPADv7SoC5b9FnWId/7YAIWuKgvUTYGm3m365Dj4OP5Vm2Bn9sRRmHThtcWSX3XIQQZGsISegkZ@cfmayu0H "Python 3 – Try It Online")
  • Makes a list comprehension of numbers from `2` to `n` of whether they factor into `n` twice, and then checks whether the list contains `True`
  • ## More friendly version (102 bytes)
  • ```python
  • def f(n):
  • for i in range(2,int(sqrt(n)+1)):
  • n=(n/i if n%i==0 else n)
  • if n%i==0:return 0
  • return 1
  • ```
  • [Try it online!](https://tio.run/##PY5BCsIwFET3PcUgSBIs2NauCrmCexGRgokN2J@apAspPXtMULr4MPx58Gb6hMHSKWpnR4x9GGDGyboA/3YhPpSG5iS6Ato6GBiC6@mpeFMaCjxDqT7UIiMgyemYIA3aGykrqJdXIJGq7dc5FWZHqAr8Ux2D8uFO8@ghca2rEk1bom3StbciiymLNyqrgMnlBXq30NphYRflWbbkuT8vO1u27kT8Ag "Python 3 – Try It Online")
  • Loops through 2 - the square root of the input number (rounded up) as `i`, and return `False` if `i` factors into the input number twice. If no instance of `i` factors twice into the input number then return `True`.
#4: Post edited by user avatar dino‭ · 2022-01-05T17:13:56Z (almost 3 years ago)
  • # [Python3](https://www.python.org/), 59 bytes
  • ```python
  • lambda n:not 1in[n%i==0 and (n/i)%i==0 for i in range(2,n)]
  • ```
  • [Try it online!](https://tio.run/##PYvBCsIwGIPve4ogSFsY6OZOg72Cd5lDKmtdYf0723qQsWev68VASAL5lm@cHF2S9s7CyjjB2MX5iPD2sdDo7mmW9jlKUEsuojLU56SjgaQRuXM6GbFv7TwMDMFLeilelySGFFWID/rYgA59dS5RNyWaenczFJmgTPxfbYFdizcUuT6stLVY2U0FBqOhOQmoOSiwq2PbQaQf "Python 3 – Try It Online")
  • Makes a list comprehension of numbers from `2` to `n` of whether they factor into `n` twice, and then checks whether the list contains `True`
  • ## More friendly version (102 bytes)
  • ```python
  • def f(n):
  • for i in range(2,int(sqrt(n)+1)):
  • n=(n/i if n%i==0 else n)
  • if n%i==0:return 0
  • return 1
  • ```
  • [Try it online!](https://tio.run/##PY5BCsIwFET3PcUgSBIs2NauCrmCexGRgokN2J@apAspPXtMULr4MPx58Gb6hMHSKWpnR4x9GGDGyboA/3YhPpSG5iS6Ato6GBiC6@mpeFMaCjxDqT7UIiMgyemYIA3aGykrqJdXIJGq7dc5FWZHqAr8Ux2D8uFO8@ghca2rEk1bom3StbciiymLNyqrgMnlBXq30NphYRflWbbkuT8vO1u27kT8Ag "Python 3 – Try It Online")
  • Loops through 2 - the square root of the input number (rounded up) as `i`, and return `False` if `i` factors into the input number twice. If no instance of `i` factors twice into the input number then return `True`.
  • # [Python3](https://www.python.org/), 53 bytes
  • ```python
  • lambda n:not 1in[n%i==0==(n/i)%i for i in range(2,n)]
  • ```
  • [Try it online!](https://tio.run/##PYvBCsIwGIPve4ogSFsY6OZOg72Cd5lDKmtdYf0723qQsWev68VASAL5lm@cHF2S9s7CyjjB2MX5iPD2sdDo7mmW9jlKUEsuojLU56SjgaQRuXM6GbFv7TwMDMFLeilelySGFFWID/rYgA59dS5RNyWaenczFJmgTPxfbYFdizcUuT6stLVY2U0FBqOhOQmoOSiwq2PbQaQf "Python 3 – Try It Online")
  • Makes a list comprehension of numbers from `2` to `n` of whether they factor into `n` twice, and then checks whether the list contains `True`
  • ## More friendly version (102 bytes)
  • ```python
  • def f(n):
  • for i in range(2,int(sqrt(n)+1)):
  • n=(n/i if n%i==0 else n)
  • if n%i==0:return 0
  • return 1
  • ```
  • [Try it online!](https://tio.run/##PY5BCsIwFET3PcUgSBIs2NauCrmCexGRgokN2J@apAspPXtMULr4MPx58Gb6hMHSKWpnR4x9GGDGyboA/3YhPpSG5iS6Ato6GBiC6@mpeFMaCjxDqT7UIiMgyemYIA3aGykrqJdXIJGq7dc5FWZHqAr8Ux2D8uFO8@ghca2rEk1bom3StbciiymLNyqrgMnlBXq30NphYRflWbbkuT8vO1u27kT8Ag "Python 3 – Try It Online")
  • Loops through 2 - the square root of the input number (rounded up) as `i`, and return `False` if `i` factors into the input number twice. If no instance of `i` factors twice into the input number then return `True`.
#3: Post edited by user avatar dino‭ · 2022-01-05T17:12:38Z (almost 3 years ago)
  • # [Python3](https://www.python.org/), 61 bytes
  • ```python
  • lambda n:not 1in[not n%i and not (n/i)%i for i in range(2,n)]
  • ```
  • [Try it online!](https://tio.run/##PYvBCsIwGIPve4ogSFsY6OZOg72Cd5lDKmtdYf0723qQsWev68VASAL5lm@cHF2S9s7CyjjB2MX5iPD2sdDo7mmW9jlKUEsuojLU56SjgaQRuXM6GbFv7TwMDMFLeilelySGFFWID/rYgA59dS5RNyWaenczFJmgTPxfbYFdizcUuT6stLVY2U0FBqOhOQmoOSiwq2PbQaQf "Python 3 – Try It Online")
  • Makes a list comprehension of numbers from `2` to `n` of whether they factor into `n` twice, and then checks whether the list contains `True`
  • ## More friendly version (102 bytes)
  • ```python
  • def f(n):
  • for i in range(2,int(sqrt(n)+1)):
  • n=(n/i if n%i==0 else n)
  • if n%i==0:return 0
  • return 1
  • ```
  • [Try it online!](https://tio.run/##PY5BCsIwFET3PcUgSBIs2NauCrmCexGRgokN2J@apAspPXtMULr4MPx58Gb6hMHSKWpnR4x9GGDGyboA/3YhPpSG5iS6Ato6GBiC6@mpeFMaCjxDqT7UIiMgyemYIA3aGykrqJdXIJGq7dc5FWZHqAr8Ux2D8uFO8@ghca2rEk1bom3StbciiymLNyqrgMnlBXq30NphYRflWbbkuT8vO1u27kT8Ag "Python 3 – Try It Online")
  • Loops through 2 - the square root of the input number (rounded up) as `i`, and return `False` if `i` factors into the input number twice. If no instance of `i` factors twice into the input number then return `True`.
  • # [Python3](https://www.python.org/), 59 bytes
  • ```python
  • lambda n:not 1in[n%i==0 and (n/i)%i==0 for i in range(2,n)]
  • ```
  • [Try it online!](https://tio.run/##PYvBCsIwGIPve4ogSFsY6OZOg72Cd5lDKmtdYf0723qQsWev68VASAL5lm@cHF2S9s7CyjjB2MX5iPD2sdDo7mmW9jlKUEsuojLU56SjgaQRuXM6GbFv7TwMDMFLeilelySGFFWID/rYgA59dS5RNyWaenczFJmgTPxfbYFdizcUuT6stLVY2U0FBqOhOQmoOSiwq2PbQaQf "Python 3 – Try It Online")
  • Makes a list comprehension of numbers from `2` to `n` of whether they factor into `n` twice, and then checks whether the list contains `True`
  • ## More friendly version (102 bytes)
  • ```python
  • def f(n):
  • for i in range(2,int(sqrt(n)+1)):
  • n=(n/i if n%i==0 else n)
  • if n%i==0:return 0
  • return 1
  • ```
  • [Try it online!](https://tio.run/##PY5BCsIwFET3PcUgSBIs2NauCrmCexGRgokN2J@apAspPXtMULr4MPx58Gb6hMHSKWpnR4x9GGDGyboA/3YhPpSG5iS6Ato6GBiC6@mpeFMaCjxDqT7UIiMgyemYIA3aGykrqJdXIJGq7dc5FWZHqAr8Ux2D8uFO8@ghca2rEk1bom3StbciiymLNyqrgMnlBXq30NphYRflWbbkuT8vO1u27kT8Ag "Python 3 – Try It Online")
  • Loops through 2 - the square root of the input number (rounded up) as `i`, and return `False` if `i` factors into the input number twice. If no instance of `i` factors twice into the input number then return `True`.
#2: Post edited by user avatar dino‭ · 2022-01-05T17:11:13Z (almost 3 years ago)
  • # [Python3](https://www.python.org/), 102 bytes
  • ```python
  • def f(n):
  • for i in range(2,int(sqrt(n)+1)):
  • n=(n/i if n%i==0 else n)
  • if n%i==0:return 0
  • return 1
  • ```
  • [Try it online!](https://tio.run/##PY5BCsIwFET3PcUgSBIs2NauCrmCexGRgokN2J@apAspPXtMULr4MPx58Gb6hMHSKWpnR4x9GGDGyboA/3YhPpSG5iS6Ato6GBiC6@mpeFMaCjxDqT7UIiMgyemYIA3aGykrqJdXIJGq7dc5FWZHqAr8Ux2D8uFO8@ghca2rEk1bom3StbciiymLNyqrgMnlBXq30NphYRflWbbkuT8vO1u27kT8Ag "Python 3 – Try It Online")
  • Loops through 2 - the square root of the input number (rounded up) as `i`, and return `False` if `i` factors into the input number twice. If no instance of `i` factors twice into the input number then return `True`.
  • # [Python3](https://www.python.org/), 61 bytes
  • ```python
  • lambda n:not 1in[not n%i and not (n/i)%i for i in range(2,n)]
  • ```
  • [Try it online!](https://tio.run/##PYvBCsIwGIPve4ogSFsY6OZOg72Cd5lDKmtdYf0723qQsWev68VASAL5lm@cHF2S9s7CyjjB2MX5iPD2sdDo7mmW9jlKUEsuojLU56SjgaQRuXM6GbFv7TwMDMFLeilelySGFFWID/rYgA59dS5RNyWaenczFJmgTPxfbYFdizcUuT6stLVY2U0FBqOhOQmoOSiwq2PbQaQf "Python 3 – Try It Online")
  • Makes a list comprehension of numbers from `2` to `n` of whether they factor into `n` twice, and then checks whether the list contains `True`
  • ## More friendly version (102 bytes)
  • ```python
  • def f(n):
  • for i in range(2,int(sqrt(n)+1)):
  • n=(n/i if n%i==0 else n)
  • if n%i==0:return 0
  • return 1
  • ```
  • [Try it online!](https://tio.run/##PY5BCsIwFET3PcUgSBIs2NauCrmCexGRgokN2J@apAspPXtMULr4MPx58Gb6hMHSKWpnR4x9GGDGyboA/3YhPpSG5iS6Ato6GBiC6@mpeFMaCjxDqT7UIiMgyemYIA3aGykrqJdXIJGq7dc5FWZHqAr8Ux2D8uFO8@ghca2rEk1bom3StbciiymLNyqrgMnlBXq30NphYRflWbbkuT8vO1u27kT8Ag "Python 3 – Try It Online")
  • Loops through 2 - the square root of the input number (rounded up) as `i`, and return `False` if `i` factors into the input number twice. If no instance of `i` factors twice into the input number then return `True`.
#1: Initial revision by user avatar dino‭ · 2022-01-05T16:52:33Z (almost 3 years ago)
# [Python3](https://www.python.org/), 102 bytes
```python
def f(n):
 for i in range(2,int(sqrt(n)+1)):
  n=(n/i if n%i==0 else n)
  if n%i==0:return 0
 return 1
```
[Try it online!](https://tio.run/##PY5BCsIwFET3PcUgSBIs2NauCrmCexGRgokN2J@apAspPXtMULr4MPx58Gb6hMHSKWpnR4x9GGDGyboA/3YhPpSG5iS6Ato6GBiC6@mpeFMaCjxDqT7UIiMgyemYIA3aGykrqJdXIJGq7dc5FWZHqAr8Ux2D8uFO8@ghca2rEk1bom3StbciiymLNyqrgMnlBXq30NphYRflWbbkuT8vO1u27kT8Ag "Python 3 – Try It Online")

Loops through 2 - the square root of the input number (rounded up) as `i`, and return `False` if `i` factors into the input number twice. If no instance of `i` factors twice into the input number then return `True`.