您的位置:首页 > 其它

POJ 1426 Find The Multiple

2015-02-27 22:34 267 查看
题意:输入一个200以内的正整数,输出任意一个只有1和0组成的100位以内的这个数的倍数

链接:http://poj.org/problem?id=1426

思路:枚举每一位,判断是否能被n整除即可

注意点:可证明这个数一定在long long范围内,不需要高精度

以下为AC代码:

Run IDUserProblemResultMemoryTimeLanguageCode LengthSubmit Time
13917588luminous111426Accepted740K157MSG++1160B2015-02-27 22:36:31
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <vector>
#include <deque>
#include <list>
#include <cctype>
#include <algorithm>
#include <climits>
#include <queue>
#include <stack>
#include <cmath>
#include <map>
#include <set>
#include <iomanip>
#include <cstdlib>
#include <ctime>
#define ll long long
#define ull unsigned long long
#define all(x) (x).begin(), (x).end()
#define clr(a, v) memset( a , v , sizeof(a) )
#define pb push_back
#define mp make_pair
#define read(f) freopen(f, "r", stdin)
#define write(f) freopen(f, "w", stdout)
using namespace std;
//const double pi = acos(-1);
//const double eps = 1e-10;
//const int dir[[4][2] = { 1,0, -1,0, 0,1, 0,-1 };
ll n;
int k;
bool flag;
void dfs ( ll x, int len )
{
if ( flag )return;
if ( len > 18 )return;
if ( x % n == 0 ){
cout << x << endl;
flag = 1;
return;
}
dfs ( x * 10, len + 1 );
dfs ( x * 10 + 1, len + 1 );
}
int main()
{
ios::sync_with_stdio( false );
while ( cin >> n && n ){
flag = 0;
dfs ( 1LL, 0LL );
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: