View Code of Problem 442

#include<iostream>
using namespace std;
int main(){
	int t;cin>>t;
	while(t--){
		int x,d=0;cin>>x;
		for(int i=7;i<1000;++i){
			if(i%7==0){
				++d;
				if(d==x){
					cout<<i-x+1<<endl;
					break;
				}
			}
			else{
				int y=i,f=0;
				while(y!=0){
					if(y%10==7)f=1;
					y/=10;
				}
				if(f){
					++d;
					if(d==x){
					cout<<i-x+1<<endl;
					break;
					}
				}
				else
				d=0;
			}
		}
	}
}

Double click to view unformatted code.


Back to problem 442