We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Project Euler #6: Sum square difference
Project Euler #6: Sum square difference
Contest ends in
+ 0 comments c# , Could anyone understand why it didn't pass test 1?
using System; using System.Collections.Generic; using System.IO; using System.Linq; class Solution { static void Main(String[] args) { int t = Convert.ToInt32(Console.ReadLine()); for(int a0 = 0; a0 < t; a0++){ int n = Convert.ToInt32(Console.ReadLine()); int sonuc = Fonk(n); Console.WriteLine(sonuc); } } static int Fonk(int n){ int sum = 0; int sum2 = 0; int sonuc = 0; for(int i = 1; i <= n; i++){ sum += i; sum2 += i * i; } sonuc = sum * sum - sum2; return sonuc; } }
+ 0 comments JAVA 8
public static void main(String[] args) { Scanner in = new Scanner(System.in); int t = in.nextInt(); long n[] = new long[t]; long count[]= new long[10000]; long result[] = new long[t]; double result1=0; double result2=0; for(int i=0; i<t; i++){ n[i] = in.nextInt(); for(int j=0; j<n[i]; j++) { count[i]+=j+1; result2+=Math.pow(j+1,2); } result1=Math.pow(count[i], 2); result[i]=((long)(result1-result2)); result1=0; result2=0; } for(int i=0; i<t; i++) { System.out.println(result[i]); } in.close(); }
+ 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 long n1=(n*(n+1)/2); long n2=(n*(n+1)*(2*n+1))/6; by using this formula it give wrong out put 10000 by using normal traditonl method using loop gives correct answer is there any one discuss on this .
+ 0 comments Python3
for _ in range(int(input())): x = int(input()) s1 =0 s2 =0 for i in range(0,x+1): s1 += i*i for i in range(0,x+1): s2 += i s2 = pow(s2,2) print(s2-s1)
Load more conversations
Sort 248 Discussions, By:
Please Login in order to post a comment