Sherlock Holmes suspects his archenemy, Professor Moriarty, is once again plotting something diabolical. Sherlock's companion, Dr. Watson, suggests Moriarty may be responsible for MI6's recent issues with their supercomputer, The Beast.

Shortly after resolving to investigate, Sherlock receives a note from Moriarty boasting about infecting The Beast with a virus; however, he also gives him a clue—a number, . Sherlock determines the key to removing the virus is to find the largest Decent Number having digits.

A Decent Number has the following properties:

  1. Its digits can only be 3's and/or 5's.
  2. The number of 3's it contains is divisible by 5.
  3. The number of 5's it contains is divisible by 3.
  4. If there are more than one such number, we pick the largest one.

Moriarty's virus shows a clock counting down to The Beast's destruction, and time is running out fast. Your task is to help Sherlock find the key before The Beast is destroyed!

Constraints

1 =< T <= 20

1 <= N <= 100000

Input Format

 

The first line is an integer, , denoting the number of test cases.

The subsequent lines each contain an integer, , detailing the number of digits in the number.

Output Format

 

Print the largest Decent Number having digits; if no such number exists, tell Sherlock by printing -1.

Sample Input

 

4
1
3
5
11

Sample Output

 

-1
555
33333
55555533333
题目大意:组成的数:5的个数能被3整除,3的个数能被5整除,找最大的那个数,显然满足条件的数中所有的5在位的前面是最大的数。5和3的个数等于n,找满足条件的5的个数最多的那个数,
一开始设5的个数为n,判断是否满足条件,否则5的个数为n-1,一直遍历,找到满足的一组则立即结束遍历,若遍历到5的个数为0,也没有找到满足条件的一组数,则输出“-1”
 #include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std; int main(){
int t;
cin >> t;
for(int a0 = ; a0 < t; a0++){
int n;
cin >> n;
int digit_five, digit_three, flag = ;
for(int i = n; i >= ; i--){
if(i % == && (n-i) % == ){
digit_five = i;
digit_three = n - i;
flag = ;
break;
}
}
if(flag == ){
cout << "-1" << endl;
continue;
}
for(int i = ; i < digit_five; i++)
cout << '';
for(int i = ; i < digit_three; i++)
cout << '';
cout << endl;
}
return ;
}

Sherlock and The Beast的更多相关文章

  1. 【HackerRank】 Sherlock and The Beast

    Sherlock and The Beast Sherlock Holmes is getting paranoid about Professor Moriarty, his archenemy. ...

  2. 16061701(地图灯光编译Beast报错)

    [目标] 地图灯光编译报错 [思路] 1 我自己测c2_cwd_rt 附件为当时log 2 ExampleGame\BeastCache\PersistentCache 3 重新删除掉BeastCac ...

  3. [译]BEAST还是一个威胁吗?

    原文链接:https://community.qualys.com/blogs/securitylabs/2013/09/10/is-beast-still-a-threat 原文发表时间:2013. ...

  4. Chapter 1 Mr.Sherlock Holmes

    I took my degree of Doctor of Medicine in the University of London, and proceeded to Netley to go th ...

  5. Dalsa Sherlock 直连千兆网相机(通用驱动)

    支持 Sherlock 7.1.7.2,用于千兆网相机与 Sherlock 的连接. 可适用于很多厂商的相机,如:巴斯勒(Basler),JAI,堡盟相机(Baumer),灰点相机(Point Gre ...

  6. Gym - 101350A Sherlock Bones(思维)

    The great dog detective Sherlock Bones is on the verge of a new discovery. But for this problem, he ...

  7. Monster: half man, half beast and very scary.

    Monster: half man, half beast and very scary. 怪物,半人半兽很吓人.

  8. [译]缓解BEAST对TLS攻击的方式

    原文链接:https://community.qualys.com/blogs/securitylabs/2011/10/17/mitigating-the-beast-attack-on-tls 原 ...

  9. [译]SSL/TLS真的被BEAST攻击攻破了吗?真实情况是怎样的?我应该做什么?

    原文链接:https://luxsci.com/blog/is-ssltls-really-broken-by-the-beast-attack-what-is-the-real-story-what ...

随机推荐

  1. #elif

    http://baike.sogou.com/v72031124.htm?fromTitle=%23elif #else指令用于某个#if指令之后,当前面的#if指令的条件不为真时,就编译#else后 ...

  2. 自定义控件和XControl控件

    (1)LabVIEW的自定义控件,实际上就是对LabVIEW自带的控件的一种修改,但是这种修改只能改变它的外观,即大小.颜色.位置等等,但是功能是改变不了的.如你对一个按钮进行自定义控件,无论怎么改, ...

  3. thymeleaf比较符号问题

    比较器与平等: 值表达可以是>.<.> =.< =符号,像往常一样,也是= =和!=操作符可以用来检查平等,但是>.<.> =.< =不能用,要用gt ...

  4. 网络子系统53_ip协议分片重组_内存阈值

    //调用路径:ip_defrag->ip_evictor // 分片重组时,可使用内存上下限: // 1.sysctl_ipfrag_high_thresh 可用内存上限 // 2.sysctl ...

  5. C++ API设计

    <C++ API设计> 基本信息 作者: (美)Martin Reddy    译者: 刘晓娜 臧秀涛 林健 丛书名: 图灵程序设计丛书 出版社:人民邮电出版社 ISBN:97871153 ...

  6. Android中回调接口的使用

    MainActivity如下: package cn.testcallback; import android.os.Bundle; import android.app.Activity; /** ...

  7. UI进阶 动画

    前言:所谓动画,即应用界面上展示的各种过渡效果,不过其实没有动画并不影响我们产品的功能实现 一.动画 1.动画可以达到的效果 传达状态 提高用户对直接操作的感知 帮助用户可视化操作的结果 2.使用动画 ...

  8. SqlServer教程:经典SQL语句集锦

    SQL分类: DDL—数据定义语言(CREATE,ALTER,DROP,DECLARE) DML—数据操纵语言(SELECT,DELETE,UPDATE,INSERT) DCL—数据控制语言(GRAN ...

  9. MyBatis之二:简单增删改查

    这一篇在上一篇的基础上简单讲解如何进行增删改查操作. 一.在mybatis的配置文件conf.xml中注册xml与注解映射 <!-- 注册映射文件 --> <mappers> ...

  10. 怎样在osg中动态的设置drawable的最近最远裁剪面

    // draw callback that will tweak the far clipping plane just    // before rendering a drawable.    s ...