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++; }
相关文章推荐
- zoj 1889 ones 数学
- ZOJ 1889 Ones
- zoj 1889 ones (同余定理)
- ZOJ - 1889 Ones
- zoj 1889 Ones
- ZOJ 1889 Ones
- zoj 1889 Ones(Mark~~)
- zoj 1889 Ones
- zoj 1889 Ones
- zoj 1889 Ones
- ZOJ 1889 Ones
- ZOJ 1629 Counting Triangles(数学题 递推)
- zoj 3716 Ribbon Gymnastics (思维数学题)
- ZOJ Saddle Point 数学思维题
- [简单数学]ZOJ 2969 Easy Task
- ZOJ 3179 Calculate With Abacus(数学啊 )
- zoj 1889
- zoj 3706 Break Standard Weight(数学题)
- ZOJ 3488 Conic Section(数学啊 )
- ZOJ 1128 Atlantis(几何数学)