2 条题解

  • 1
    @ 2025-12-6 8:42:24

    这题很简单,只需要根据题目,计算出第i个数的数值其实是i^2-1,再根据前n项和公式求出第n个数的结果为n^2;但是注意n最大为10^11,n^2即使开long long 也很容易超,因此不能直接n^2%(1e9+7);只需要根据数学公式推到出其等于((n^2)%(1e9+7)*(n^2)%(1e9+7))%(1e9+7),即可求出

    • 0
      @ 2025-10-12 21:05:06
      #include <bits/stdc++.h>
      using namespace std;
      #define int long long
      const int mod = 1e9 + 7;
      void solve(){
          int n; cin >> n;
          int ans = ((n % mod) * (n % mod)) % mod;
          cout << ans << endl;
      }
      signed main(){
          ios::sync_with_stdio(0);
          cin.tie(0), cout.tie(0);
          int T = 1;
          // cin >> T; 
          while(T--){
              solve();
          }
          return 0;
      }
      
      
      • @ 2025-10-12 21:05:27

        打表:

            int sum = 0;
            for(int i = 1; i <= 10; i++){
                int ans = i*i - ((i+1) * (i+1) - 4*i);
                sum += ans;
                cout << sum << endl;
            }
        
      • @ 2025-10-12 21:05:42
           1: 1
           2: 4
           3: 9
           4: 16
           5: 25
           6: 36
           7: 49
           8: 64
           9: 81
           10: 100
        
      • @ 2025-10-12 21:05:56

        把前十个答案打印出来,发现规律很明显了,然后注意开long long 就行

    • 1

    信息

    ID
    1133
    时间
    1000ms
    内存
    256MiB
    难度
    7
    标签
    (无)
    递交数
    51
    已通过
    13
    上传者