题解:P12590 橙色预警嘻

· · 题解

P12590 橙色预警嘻 题解

首先本蒟蒻刚开始还没理解题意,读了好久才明白,但还是不会啊 QWQ ,只好先打表:

#include <bits/stdc++.h>
#define int long long//保险起见开long long,反正炸不了
using namespace std;
const int N = 1e5 + 5, mod = 1e5;
int a[N];
int ksm(int x, int y) {
    int res = 1;
    while (y != 0) {
        if (y % 2 == 1) {
            res = res * x % mod;
        } 
        x = x * x % mod;
        y /= 2;
    }
    return res;
}//快速幂 
signed main() {
//  freopen(".in", "r", stdin);
//  freopen(".out", "w", stdout);
    for (int i = 1; i <= 1e5; i++) {
        a[i] = (ksm(3, i) + ksm(5, i)) % mod;
        cout << a[i] << ' ';
    }
    return 0;
}

马蜂特臭

我们输出发现,感觉有点规律啊,用 Ctrl+F 我们细致的眼睛发现,这居然是周期的!

8 34 152 706 3368 16354 80312...... 40706 3368 16354 80312...... 40706 3368 16354 80312...... 40706 3368 16354 80312...... 40706.....

显然周期是这个:

3368 16354 80312...... 40706

那既然知道了 a 数组是周期的,那么问题就转化成了求这个周期的长度。怎么求呢?易知我们的周期的长度是不会炸的,那么可以把周期输进 string 中,用 getline 函数读取就好啦。

#include <bits/stdc++.h>
#define int long long
using namespace std;
signed main() {
//  freopen(".in", "r", stdin);
//  freopen(".out", "w", stdout);
    string s;
    getline(cin, s);//输入字符串
    int ans = 0;
    for (int i = 0; i < s.size(); i++) {
        if (s[i] == ' ') {//有一个数字被读进来了
            ans++;//累加答案
        }
    }
    cout << ans + 1;//+1是因为最后一个整数没读到
    return 0;
}

把我们的周期输进去,得到了一个这样的一个数字:

2500

那输出就好啦。

#include <bits/stdc++.h>
#define int long long
using namespace std;
signed main() {
//  freopen(".in", "r", stdin);
//  freopen(".out", "w", stdout);
    cout << 2500;
    return 0;
}

证明的话还是建议你们去看别的题解,因为这种做法只限于考场策略。

完结撒花!