Codeforces Round #158 (Div. 2) A - Adding Digits

题目: http://codeforces.com/contest/260/problem/A

思路:a%b==0 => a*10^n%b==0

这题一开始忽略了一句话  If there are multiple possible answers, print any of them.

想了半天觉得答案不只一种啊

然后看到n的范围就知道这题不可能一位位算

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

int a,b,n;
int main()
{
    cin >> a>>b>>n;
    a*=10;
    int flag=0;
    for(int i=0;i<10;i++)
    {
        if(a%b==0) 
        {
            flag=1;    
            break;
        }
        a++;
    }
    if(flag)
    {
        cout << a;
        for(int i=0;i<n-1;i++)
        {
            cout<<"0";
        }
        cout << endl;
    }
    else
    {
        cout << "-1"<<endl;
    }
return 0;
}

转载于:https://www.cnblogs.com/danielqiu/archive/2013/01/16/2863078.html

猜你喜欢

转载自blog.csdn.net/weixin_34354173/article/details/93795248