24h購物| | PChome| 登入
2012-11-03 17:28:13| 人氣648| 回應0 | 上一篇 | 下一篇

[ACM-ICPC][本地建表] 5726 - Twin Apparent Primes!!

推薦 0 收藏 0 轉貼0 訂閱站台

Prime numbers have very interesting applications in Computer Science. This problem is obviously related with prime numbers but you need to know the following two definitions to solve this problem.

 

Apparent Prime: A positive number that is not divisible by all integer numbers greater than 1 and less than or equal to t is called apparent prime. The value of t will be supplied for you.

 

Twin Apparent Primes: If the difference of two apparent primes is 2 then they are called twin apparent primes.

 

Given the value of n and t you will have to find two n-digit apparent prime numbers p and (p+2).

 

Input

The input file contains at most 1001 lines of inputs. Each line contains two positive integers n (3500 ≤ n ≤ 5000) and t (t ≤ 8000).

 

Input is terminated by a line containing two zeroes. These two numbers are of course invalid input and should not be processed.

 

Output

For each line of input produce one line of output. This line contains an n-digit apparent prime number p, such that (p+2) is also an apparent prime. If here is more than one such number, anyone will do.

 

Sample input

Sample output

2 6

0 0

 

17


Although n>=3500, in the sample n=2 so that the output fits in reasonable space.



建出所有小於等於8000質數的乘積-1。
不足位數補 9 即可。

#include <stdio.h>
#include <math.h>
#include <string.h>
int main() {
    int n, t, i;
    char ans[5000] = "1362562009103927516181790697908402630750268671988097668597117777450735527854639563576129618821798992014472833017048220559487787332344887282230720904047852471891741753346204386294918168151772890219951332270658298362660628186041512451772056484590387955087269949474982621146017318119491514546991869648271932400619948094456004043863022635968291120563590445675620901082407103155632986806704622532360840996825822558112672762642769345471035445915290713846270177699946569990328845263378446890842244919134227178993535032097598933440284513533156850116646864071210887303064572399454044798215356122183768500016975527452811120829055353508873584616106772179431159176829871423795935837208781449105929847742228858623446965112744786500825318410061684214243018248670821856737745340051235323187388447395528370641514796690015328002186543346176418786428113554982377747750459154098816479022495074749948815916254425359841265834127833546047456669442589926588844444922830927760126283633937631418702992007132164919929784148317727124333587746382714421216543612197150137622585279680391455004874966637706966516495200756226943452775660642961859201372096194090880178644373327229364547555094819141164426781615856863542701027014969283148506566268029740493028162373587793880672289813797933830108657007642053845972662246051600529779947565703828023315859592096457917732729591995903040051900646050868107512178982246708590347390585704483207863574772553374585425239528990706699173928105285592228478808933344599927710007262458948996293160335797191503164952754774471916413324017078293689947337092097467528677048657651346838808649621500623361359421922543101040323830989265750551803777089044970554805845167358790289673219052375937503614023926370043950397473459412342796452229268349657428721734248423170315775660440693281771023546954339712976513099919898547513407034283025655932384054685870559490732064701561366809174652666891209304000566270609888954422544643269996778334022627705080772051686234408177703504523886131388215284057807612073921935686708448102325517865347532698085025812149137008551409761660546977028182628904984164522480413763163473444936190410788545002445098716963737426343654343863804518392328900035744402556546554738042170307121476048759772014918277984551382580802818096683708110840203514456294196609403904039968085613684728131383809454886244668692580199423153990355161292678391702923641538928845076539952784517286775221562951457542118453128350253051648156518303972918601076931830811719959537023497356410891590928247194878378993677585975261778405687390400573837814167923994619393103283197573985917144752885227420610966097252900845504997761776165937149565279201367059514630079398226833914594640925654594099332130992890674350009433450190926447371744195946316728602762150446481952761126798526465008387398169540737573005951293228032968596650369249451438534373421771951794003458284225722862311693838382865417712259815218216427261492909937096315326034991252139050863745845552317578401492133736760959903844939517570914321584607259184838588598504723420790120682862002354558119184334335654005093812000916556410872099455799342256430716777000794024994267080595230550559599878287525904667925309341545792784991695240039678222714254310070998733670792584665944663600074162960031415482009747966600343028613989131563952532883237176142662010485835316842973245031403070650871264359968240370714635457273644027101396300083268726582240179003628517080189317969878575736789";
    while(scanf("%d %d", &n, &t) == 2) {
        if(n == 0)  break;
        printf("%s", ans);
        for(i = n-strlen(ans); i > 0; i--)
            printf("9");
        puts("");
    }
    return 0;
}

台長: Morris
人氣(648) | 回應(0)| 推薦 (0)| 收藏 (0)| 轉寄
全站分類: 不分類 | 個人分類: UVA |
此分類下一篇:[ACM-ICPC][搜索] 5729 - Coalescing Continents
此分類上一篇:[ACM-ICPC] 5725 - Fun Coloring

是 (若未登入"個人新聞台帳號"則看不到回覆唷!)
* 請輸入識別碼:
請輸入圖片中算式的結果(可能為0) 
(有*為必填)
TOP
詳全文