1091. Tmutarakan Examstime limit:1.0 Second Memory limit:64 mbuniversity of New Tmutarakan trains the first-class specialists in mental arithmetic. To enter the University should master arithmetic perfectly. One of the entrance exams at the divisibility Department is the following. Examinees is asked to findKDifferent numbers that has a common divisor greater than 1. All numbers in each set should not exceed a given numberS. The numbersKandSis announced at the beginning of the exam. To exclude copying (the Department are the most prestigious in the town!) each set of numbers are credited only once Who submitted it first). Last year these numbers wereK=25 andS=49 and, unfortunately, nobody passed the exam. Moreover, it is proved later by the best minds of the Department that there does not exist sets of numbers with the Require D Properties. To avoid embarrassment this year, the dean of asked for your help. You should find the number of sets ofKDifferent numbers, each of the numbers not exceedingS, which has a common divisor greater than 1. Of course, the number of such sets equals the maximal possible number of new students of the department.inputthe input con Tains numbersKandS(2≤K≤S≤50). Outputyou should output the maximal possible number of the Department ' s new students If this number is does not exceed 10000 Which is the maximal capacity of the Department, otherwise you should output 10000.Sample
problem Author:Stanislav Vasilyev problem Source:USU Open Collegiate Programming Contest March ' 2001 Senior SessionTags:Number theory()difficulty:480 Printable version Submit solution Discussion (29) My Submissions All submissions (8523) all accepted submissions (2607) Solutions Rating (2071) |
©2000–2016 timus Online Judge Team. All rights reserved.
Idea: Same as http://www.cnblogs.com/zzuli2sjy/p/5467008.html;
1#include <stdio.h>2#include <string.h>3#include <iostream>4#include <algorithm>5#include <queue>6 using namespacestd;7typedefLong LongLL;8 BOOLprime[ -];9 intans[ -];Ten intcoutt[10000]; OneLL dp[ -][ -]; A intask[ -]; - intid[ -]; -queue<int>que; the intMainvoid) - { - inti,j,k,p,q; -dp[0][0]=1; +dp[1][0]=1; -dp[1][1]=1; + for(i=2; i<= -; i++) A { at for(j=0; j<= -; J + +) - { - if(j==0|| i==j) - { -dp[i][j]=1; - } in Elsedp[i][j]=dp[i-1][j-1]+dp[i-1][j]; - } to } + for(i=2; i<=Ten; i++) - { the if(!Prime[i]) * { $ for(J=i; i*j<= -; J + +)Panax Notoginseng { -prime[i*j]=true; the } + } A } the intCnt=0; + for(i=2; i<= -; i++) - { $ if(!Prime[i]) $ { -ans[cnt++]=i; - } the } - while(SCANF ("%d%d", &p,&q)! =EOF)Wuyi{ints; thememset (Coutt,0,sizeof(Coutt)); - for(s=2; s<=q; s++) Wu { - intCc=s; About intflag=0; $ intt=0; - while(cc>1) - { - if(cc%ans[t]==0&&flag==0) A { +flag=1; the Que.push (ans[t]); -Cc/=Ans[t]; $ } the Else if(cc%ans[t]==0) the { theCc/=Ans[t]; the } - Else in { thet++; theflag=0; About } the } the intvv=0; the while(!que.empty ()) + { -ask[vv++]=Que.front (); the Que.pop ();Bayi } the for(i=1; I<= (1<<VV)-1; i++) the { -LL sum=1; - intDd=0; the for(j=0; j<vv; J + +) the { the if(i& (1<<j)) the { -dd++; thesum*=Ask[j]; the } the }94id[sum]=DD; thecoutt[sum]++; the the }98 } AboutLL summ=0; - for(i=2; i<= -; i++)101 {102 if(id[i]%2&&coutt[i]>=p)103 {104summ+=Dp[coutt[i]][p]; the }106 Else if(coutt[i]>=p) summ-=Dp[coutt[i]][p];107}if(summ>=10000) summ=10000;108printf"%lld\n", Summ);109 } the return 0;111}
1091. Tmutarakan Exams