题解 P1662 【数7】
zhangmohan · · 题解
include<bits/stdc++.h>
using namespace std; int num[20]; int c=0; int n; inline void add(){ num[1]++; if(num[1]==8) c--; if(num[1]==7) c++; int pos=1; while(num[pos]>9){ num[pos]%=10; pos++; num[pos]++; if(num[pos]==8) c--; if(num[pos]==7) c++; } } int fx[]={1,1,-1,-1,1,1,-1,1,-1,1}; int b[]={0,548,866,892,64,1303,97,1278,1278,960}; int main(){
int x;
scanf("%d",&x);
int k=x/100000000;
n=100000000*k;
int pos=b[k],dic=fx[k];
while(1){
pos=(pos+dic+1336)%1337+1;
n++;
add();
if(n%7==0||c>0) dic=-dic;
if(n==x) break;
}
printf("%d",pos);
return 0;
}