Skip to content
TheChatArchiveThe Chat Archive
Qwenqwen3-235b-a22b-no-thinking· Alibaba (Qwen)Hugging Face LMArena Human Preference 140K

class Solution {\n static long fibSum(long N) {\n long MOD = 1000000007;\n if (N == 0)…

From a Chatbot Arena battleThe same person sent this prompt to two anonymous models at once. Compare it with Mistralmistral-medium-2505’s answer.
  1. User

    class Solution {\n static long fibSum(long N) {\n long MOD = 1000000007;\n if (N == 0) return 0;\n if (N == 1) return 1;\n\n long a = 0;\n long b = 1;\n long sum = 1;\n\n for (long i = 2; i <= N; i++) {\n long c = (a + b) % MOD;\n sum = (sum + c) % MOD;\n\n a = b;\n b = c;\n }\n\n return sum;\n }\n}

    convert java code to javascript

  2. Qwen Assistant

    Here's the JavaScript equivalent of your Java code:

    function fibSum(N) {
        const MOD = 1000000007;
    
        if (N === 0) return 0;
        if (N === 1) return 1;
    
        let a = 0;
        let b = 1;
        let sum = 1;
    
        for (let i = 2; i <= N; i++) {
            let c = (a + b) % MOD;
            sum = (sum + c) % MOD;
    
            a = b;
            b = c;
        }
    
        return sum;
    }
    

    Notes:

    • In JavaScript, we don't specify types like long. Numbers can be treated as integers and will work fine for reasonably large values.
    • The logic remains exactly the same: computing the Fibonacci numbers iteratively and maintaining a running sum modulo 109+710^9 + 7.
    • Use let or const instead of long for variable declarations.

    Example Usage:

    console.log(fibSum(0)); // 0
    console.log(fibSum(5)); // 1 + 1 + 2 + 3 + 5 = 12
    console.log(fibSum(100000)); // very large, but handled safely due to mod
    

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.