Project Euler #5: Smallest multiple
Project Euler #5: Smallest multiple
+ 0 comments hey can someone help me out with this problem? im new to competitive programming and my friend sent me this. he wants me to solve it but as i said, im still new so can yall teach me? here is the problem https://www.hackerrank.com/newbie-challenge
+ 0 comments import sys import math
t = int(input().strip()) for a0 in range(t): n = int(input().strip())
arr = [] for item in range(1,n+1): arr.append(item) print(math.lcm(*arr))
+ 0 comments hey can someone help me out with this problem? im new to competitive programming and my friend sent me this. he wants me to solve it but as i said, im still new so can yall teach me? here is the problem https://www.hackerrank.com/newbie-challenge
+ 0 comments public static void main(String[] args) { Scanner in = new Scanner(System.in); int t = in.nextInt(); for(int a0 = 0; a0 < t; a0++){ int n = in.nextInt(); System.out.println(lcm(n));
} } public static int lcm(int n){ int result=1; for(int i=2;i<=n;i++){ result=result*i/gcd(result,i); } return result; } public static int gcd(int n,int o){ if(o==0) return n; return gcd(o,n%o); }
+ 0 comments import sys
import math
for _ in range(int(input())): x = int(input()) result = 1 for i in range(1, x + 1): result = result * i // math.gcd(result, i) print(result)
Sort 243 Discussions, By:
Please Login in order to post a comment