您的位置:首页 > 其它

zoj 1889 ones 数学

2017-08-11 11:30 337 查看
OnesTime Limit:2 Seconds     Memory Limit:65536 KB Given any integer 0 <= n <= 10000 not divisible by 2 or 5, some multiple of n is a number which in decimal notation is a sequence of 1's. How many digits are in the smallest such a multiple of n?Sample Input379901 Sample Output3612

做题经验:把1...1(n)转化为9...9(n)/9,再转化为1...0(n+1)-1。如1111换成9999=10000-1

然后就可以结合数学姿势同余乱搞了。
#include<cstdio>
#include<cstdlib>
#include<iostream>
using namespace std;

int main()
{
int n;
while(cin>>n)
{
if(n==0){cout<<1<<endl;continue;}//这一行不要也,但题目说了n=0是存在的,以防
4000
万一
n*=9;
int cnt=1;
long long ans=9;
while(ans%n!=0)
{
ans=(((ans+1)*10)%n-1)%n;
cnt++;
}
cout<<cnt<<endl;
}
return 0;
}
当然直接搞也可以,如下(暗含了秦九韶思想)
while(i%n)          {              i=(i*10+1)%n;              j++;          }  

                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: