upc組隊賽15 Supreme Number【打表】

Supreme Number

題目鏈接

題目描述

A prime number (or a prime) is a natural number greater than 1 that cannot be formed by multiplying two smaller natural numbers.
Now lets define a number N as the supreme number if and only if each number made up of an non-empty subsequence of all the numeric digits of N must be either a prime number or 1.
For example, 17 is a supreme number because 1, 7, 17 are all prime numbers or 1, and 19 is not, because 9 is not a prime number.
Now you are given an integer N (2≤N≤10100), could you find the maximal supreme number that does not exceed N?

輸入

In the first line, there is an integer T(T≤100000) indicating the numbers of test cases.
In the following T lines, there is an integer N (2≤N≤10100).

輸出

For each test case print "Case #x: y", in which x is the order number of the test case and y is the answer.

樣例輸入

2
6
100

樣例輸出

Case #1: 5
Case #2: 73

題解

通過打表發現滿足條件的最大數為317
坑點在于石油大把10^100寫成10100

代碼

#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for(int i=a;i<n;i++)
#define scac(x) scanf("%c",&x)
#define sca(x) scanf("%d",&x)
#define sca2(x,y) scanf("%d%d",&x,&y)
#define sca3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define scl(x) scanf("%lld",&x)
#define scl2(x,y) scanf("%lld%lld",&x,&y)
#define scl3(x,y,z) scanf("%lld%lld%lld",&x,&y,&z)
#define pri(x) printf("%d\n",x)
#define pri2(x,y) printf("%d %d\n",x,y)
#define pri3(x,y,z) printf("%d %d %d\n",x,y,z)
#define prl(x) printf("%lld\n",x)
#define prl2(x,y) printf("%lld %lld\n",x,y)
#define prl3(x,y,z) printf("%lld %lld %lld\n",x,y,z)
#define ll long long
#define LL long long
#define pb push_back
#define mp make_pair
#define P pair<int,int>
#define PLL pair<ll,ll>
#define PI acos(1.0)
#define eps 1e-6
#define inf 1e17
#define INF 0x3f3f3f3f
#define MOD 998244353
#define mod 1e9+7
#define N 1000005
const int maxn=10000;
// int prime[1000100]; //打表程序
// bool book[1000100];
// int top;
// void isprime()
// {
//    memset(book, true, sizeof(book));
//    book[1] = false;
//    for(int i=2;i<maxn;i++)
//    {
//      if(book[i])
//      {
//         for(int j=i+i;j<maxn;j+=i)
//         {
//            book[j] = false;
//         }
//      }
//    }
//    for(int i=2;i<=maxn;i++)
//    {
//      if(book[i])
//      {
//         prime[++top] = i;
//      }
//    }
// }
// int main()
// {
//   int n;
//   isprime();
//   book[1] = true;
//   for(int i = 10000; i >= 1000;i--)
//   {
//     if(book[i])
//     {
//       int temp = i;
//       int a = temp%10;
//       temp/=10;
//       int b = temp%10;
//       temp/=10;
//       int c = temp%10;
//       temp /=10;
//       int d = temp;
//       printf("%d %d %d %d\n",d,c,b,a);
//       if(book[a] && book[b] && book[c]  && book[d]  && book[d*10+c] && book[d*10+b] && book[d*10+a] && book[c*10 + b] && book[c*10 + a] && book[b*10 + a] && book[d*100 + c*10 +b] && book[d*100 + c*10 +a] && book[d*100 + b*10 +a] && book[c*100 + b*10 +a])
//       {
//         printf("%d\n",i);
//       }
//     }
//   }
// }
int a[100] = {1,2,3,5,7,11,13,17,23,31,37,53,71,73,113,131,137,173,311,317,10101};
int main()
{int n;int t;sca(t);int cas = 1;string s;while(t--){// sca(n);n = 0;cin>>s;if(s.length()>4){printf("Case #%d: %d\n",cas++,317);continue;}rep(i,0,s.length()){n = n*10+s[i]-'0';}rep(i,0,21){if(n<a[i]){printf("Case #%d: %d\n",cas++,a[i-1]);break;}}}return 0;
}

轉載于:https://www.cnblogs.com/llke/p/10809660.html

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/275209.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/275209.shtml
英文地址,請注明出處:http://en.pswp.cn/news/275209.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

CSS3實踐之路(一):CSS3之我觀

CSS 的英文全稱Cascading Style Sheets&#xff0c;中文意思是級聯樣式表,通過設立樣式表&#xff0c;可以統一地控制HMTL中各DOM元素的顯示屬性。級聯樣式表可以使人更能有效地控制網頁外觀。使用級聯樣式表&#xff0c;可以擴充精確指定網頁元素位置&#xff0c;外觀以及創建…

18個項目必備的JavaScript代碼片段——數組篇

大家好&#xff0c;我是若川。最近組織了源碼共讀活動&#xff0c;感興趣的可以加我微信 ruochuan12 參與&#xff0c;目前近3000人參與&#xff0c;0-5年工作經驗的都可以參與學習。1.chunk轉換二維數組將數組&#xff08;array&#xff09;拆分成多個數組&#xff0c;并將這些…

美學評價_卡美學的真正美

美學評價In collectible card games like Hearthstone, Legends of Runeterra, and Magic: The Gathering, the aesthetic of the cards is indubitably one of the greatest highlights for many, if not all players. Although the game loop is reliant on physically build…

好程序員web前端分享CSS Bug、CSS Hack和Filter學習筆記

為什么80%的碼農都做不了架構師&#xff1f;>>> CSS Bug、CSS Hack和Filter學習筆記 1)CSS Bug:CSS樣式在各瀏覽器中解析不一致的情況&#xff0c;或者說CSS樣式在瀏覽器中不能正確顯示的問題稱為CSS bug. 2)CSS Hack: CSS中&#xff0c;Hack是指一種兼容CSS在不同…

as3 淺復制 深復制

基元數據類型&#xff1a;boolean、int、uint、number、string 兩種復雜數據類型&#xff1a;array、object 當數組元素全部是基元數據類型時&#xff0c;即全部是值類型時&#xff0c;是沒有淺復制和深復制的區別。 當數組元素全部是復雜數據類型&#xff0c;即引用類型時&…

碎片化學前端,促進技術提升,我推薦這些

大家好&#xff0c;我是若川。眾所周知&#xff0c;關注公眾號可以了解學習掌握技術方向&#xff0c;學習優質好文&#xff0c;落實到自己項目中。還可以結交圈內好友&#xff0c;讓自己融入到積極上進的技術氛圍&#xff0c;促進自己的技術提升。話不多說&#xff0c;推薦這些…

ux和ui_設計更好的結帳體驗-UX / UI案例研究

ux和uiPlated Cuisine is a food ordering and delivery app for Plated Cuisine Restaurant founded and managed by Rayo Odusanya.Plated Cuisine是由Rayo Odusanya創建和管理的Plated Cuisine Restaurant的食品訂購和交付應用程序。 A short background about Rayo Rayo O…

Django中ajax發送post請求,報403錯誤CSRF驗證失敗解決辦法

今天學習Django框架&#xff0c;用ajax向后臺發送post請求&#xff0c;直接報了403錯誤&#xff0c;說CSRF驗證失敗&#xff1b;先前用模板的話都是在里面加一個 {% csrf_token %} 就直接搞定了CSRF的問題了&#xff1b;很顯然&#xff0c;用ajax發送post請求這樣就白搭了&…

如何在EXCEL中添加下拉框

篩選主要是將已有列的信息以下拉框的形式顯示出來 選中數據欄中的篩選按鈕即可生成 如果是想添加未有信息則如下圖步驟 首先&#xff0c;選擇你要出現下拉的區域&#xff0c;在數據欄中的選擇數據有效性 然后&#xff0c;下面對話框中&#xff0c;有效性條件中按如下設置即可&a…

每次新增頁面復制粘貼?100多行源碼的 element-ui 的新增組件功能教你解愁

1. 前言大家好&#xff0c;我是若川。最近組織了源碼共讀活動&#xff0c;感興趣的可以點此加我微信ruochuan12 參與&#xff0c;每周大家一起學習200行左右的源碼&#xff0c;共同進步。已進行三個月了&#xff0c;很多小伙伴表示收獲頗豐。想學源碼&#xff0c;極力推薦之前我…

原子設計_您需要了解的有關原子設計的4件事

原子設計重點 (Top highlight)Industries such as Architecture or Industrial Design have developed smart modular systems for manufacturing extremely complex objects like airplanes, ships, and skyscrapers. Inspired by this, Atomic Design was proposed as a syst…

深度學習 Caffe 初始化流程理解(數據流建立)

之前在簡書的文章&#xff0c;搬遷過來 ^-^ 本文是作者原創&#xff0c;如有理解錯誤&#xff0c;懇請大家指出&#xff0c;如需引用&#xff0c;請注明出處。 #Caffe FeatureMap數據流的建立 ##用語解釋 FeatureMap: 輸入的圖片信息或者經過多層處理后的圖片信息。weights: 只…

C#中的Clipboard與ContextMenuStrip應用舉例

今天&#xff0c;突然想起了怎樣在一個文本中實現復制、剪切與粘貼的功能&#xff0c;并給這些功能添加右鍵的快捷方式。于是&#xff0c;就用自己的VS2008寫了一個簡單的小應用&#xff0c;以熟悉C#中剪貼板與快捷菜單的使用。 首先&#xff0c;我們不難發現&#xff0c;剪貼板…

控制臺ui_設計下一代控制臺UI

控制臺ui游戲UX (GAMES UX) Yesterday’s Sony presentation showed us the final look of the PlayStation 5, as well as an impressive of next-gen games that will be released with it. What we didn’t get to see, however, is the new operating system and it’s use…

寫給前端新手看的一些模塊化知識

大家好&#xff0c;我是若川。最近組織了源碼共讀活動&#xff0c;感興趣的可以點此加我微信ruochuan12 進群參與&#xff0c;每周大家一起學習200行左右的源碼&#xff0c;共同進步。已進行三個月了&#xff0c;很多小伙伴表示收獲頗豐。一、 為什么需要模塊化以前沒有模塊化時…

重學前端學習筆記(八)--JavaScript中的原型和類

筆記說明 重學前端是程劭非&#xff08;winter&#xff09;【前手機淘寶前端負責人】在極客時間開的一個專欄&#xff0c;每天10分鐘&#xff0c;重構你的前端知識體系&#xff0c;筆者主要整理學習過程的一些要點筆記以及感悟&#xff0c;完整的可以加入winter的專欄學習【原文…

代碼實現照片素描_我的代碼素描之旅

代碼實現照片素描In 2018 I started the process of consistently creating and posting my code sketches online. These are small animations I make with code and post on instagram. Through these sketches I tried to visually express my ideas using color, animatio…

GCC參數詳解

轉自&#xff1a;http://www.cnblogs.com/fence/archive/2009/12/18/1627138.html GCC參數詳解 gcc and g分別是gnu的c & c編譯器 gcc/g在執行編譯工作的時候&#xff0c;總共需要4步1.預處理,生成.i的文件[預處理器cpp]2.將預處理后的文件不轉換成匯編語言,生成文件.s[編…

真效率神器,UI稿智能轉換成前端代碼,準確率極高

大家好&#xff0c;我是若川。在這充滿網絡促銷活動的幾個月&#xff0c;倍感壓力的&#xff0c;除了你的口袋&#xff0c;是否還有程序員的發量呢&#xff1f;每年的雙十一、雙十二購物狂歡節&#xff0c;各大電商平臺都會上線讓消費者充滿購買欲望的活動頁面&#xff0c;而這…

PPT圖標的正確使用和插入與編輯形狀

PPT圖標的正確使用和插入與編輯形狀 通過圖標可以以符號的形式直觀地傳遞信息。 一&#xff0c;實戰&#xff1a;在銷售工作計劃中插入圖標 PowerPoint 2016中提供了多種類型的圖標&#xff0c;用戶可根據需要在幻燈片中插入所需的圖標。 二&#xff0c;實戰&#xff1a;更改銷…