Codeforces Round #324 (Div. 2) Olesya and Rodion 构造

原题链接:http://codeforces.com/contest/584/problem/A

题意:

给你n和t,让你构造一个长度为n的数,并且被t整除

题解:

方法很多,可以乱构造。。。。。不过需要特判n=1且t=10这种特殊情况

代码:

#include<iostream>
#include<cstring>
using namespace std;

int t,n;

int main() {
    cin >> n >> t;
    if (n == 1 && t == 10) {
        cout << -1 << endl;
        return 0;
    }
    if (n == 1) {
        cout << t << endl;
        return 0;
    }
    int a = 1;
    for (int i = 0; i < n-1; i++)a = (a * 10) % t;
    cout << 1;
    for (int i = 0; i < n - 2; i++)cout << 0;
    if (t == 10 && a == 0)
        cout << 0 << endl;
    else
        cout << t - a << endl;
    return 0;
}
原文地址:https://www.cnblogs.com/HarryGuo2012/p/4858589.html