3
NEU1681 The Singles(数学)
source link: https://arminli.com/neu1681/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Armin's Blog
NEU1681 The Singles(数学)
February 07, 2016
题意:输入 a,输出最小的 n 个 1 组成的数,使这个数能整除 a(如果存在)。
思路:不断对余数乘以 10+1,直到余数已经出现停止(不存在),或者能整除(存在)。
#include<iostream> #include<cmath> #include<queue> #include<cstring> #include<string> #include<map> #include<stack> #include<set> #include<cstdio> #include<algorithm> using namespace std; int a[1000005], n; int main(){ //freopen("a.txt", "r", stdin); while(scanf("%d", &n) != EOF){ memset(a, 0, sizeof(a)); int ans = 1; int cnt = 1; int flag = 0; while(ans%n != 0){ int t = ans%n; cnt++; ans = t*10+1; if(a[t]){ flag = 1; break; } a[t] = 1; } if(flag) cout << "There is no Singles' Day!" << endl; else{ cout << "Singles' Day is on "; for(int i = 0; i < cnt; i++) cout << "1"; cout << "." <<endl; } } return 0; }
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK