1 条题解

  • 0
    @ 2026-9-30 12:54:55

    C++ :

    
    #include <cstdio>
    #include <cstring>
    #include <algorithm>
    /* 枚举 X 的所有数字排列(去重、无前导零),看是否存在 k>=2 使 perm == k*X */
    int main(){
        int G; if(scanf("%d", &G) != 1) return 0;
        while(G--){
            char s[32];
            scanf("%s", s);
            int L = (int)strlen(s);
            long long X = 0;
            for(int i=0;i<L;i++) X = X * 10 + (s[i] - '0');
            std::sort(s, s + L);
            int found = 0;
            do {
                if(s[0] == '0') continue;
                long long v = 0;
                for(int i=0;i<L;i++) v = v * 10 + (s[i] - '0');
                if(v != X && v % X == 0){ found = 1; break; }
            } while(std::next_permutation(s, s + L));
            printf("%s\n", found ? "Possible" : "Impossible");
        }
        return 0;
    }
    
    
    • 1

    信息

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