"bzoj-1853&2393" Lucky number &cirno the perfect arithmetic classroom tolerance principle + burst search + pruning

Source: Internet
Author: User
Tags cmath

1853: [Scoi2010] Lucky number time limit:2 Sec Memory limit:64 MB
submit:1817 solved:665
[Submit] [Status] [Discuss] Description in China, many people think of 6 and 8 as lucky numbers! LXHGWW also thought, so he defined his "lucky number" is a decimal representation of only the numbers 6 and 8 of those numbers, such as 68,666,888 are "lucky number"! But this "lucky number" is always too small, for example, in the [1,100] range of only 6 (6,8,66,68,86,88), so he defined a "approximate lucky number." LXHGWW rules that the "lucky number" multiples are "approximate lucky numbers", of course, any "lucky number" is also "approximate lucky number", such as 12, 16,666 are "approximate lucky number." Now LXHGWW want to know the number of "approximate lucky numbers" within a closed interval [a, b]. Input data is a row, including 2 numbers A and boutput output data is a row, including 1 numbers, indicating the number of "approximate lucky numbers" in the closed interval [a, b], sample input "Sample Input 1"
1 10
"Sample Input 2"
1234 4321
Sample Output "Sample Output 1"
2
"Sample Output 2"
809
HINT

"Data Range"
For 30% data, guarantee 1 < =a < =b < =1000000
For 100% data, guarantee 1 < =a < =b < =10000000000

Source

Day1

2393:cirno's Perfect arithmetic classroom Time limit:10 Sec Memory limit:128 MB
submit:299 solved:183
[Submit] [Status] [Discuss] Description~cirno found a Baka number, this number ~ only contains 2 and ⑨ two kinds of numbers ~ ~ Now Cirno want to know ~ ~ a range of how many numbers can be divided by Baka number ~ but Cirno so genius of the Goblin only disdain to count it can only rely on the smart you. Input line integer L R (1 < L < R < 10^10) output a positive integer that represents the answer that is asked by the sample Input1 100
Sample Output -Hintsourcesolution

The principle of tolerance and repulsion--search pruning

First preprocessing the number of Baka (Lucky number), then go back to the weight (delete can be divisible by other Baka number)

There is a conclusion before the allowance :

n the number of multiples of a or B =N/A+N/B-N/LCM (A, A, a), i.e. a in multiples of n +b within n multiples of A and b two in the same multiples of n (so starting from least common multiple)

Then you can let go, search + pruning can be a one of the most effective pruning is the first to say that the weight can also be more than the part of R directly ignored

By the way :baka number can be normal A, lucky number that question, need to change to unsigned long long, otherwise will tle (but this machine clearly run as fast)

Code
#include <iostream>#include<cstdio>#include<cmath>#include<cstring>#include<algorithm>using namespacestd;#defineMAXN 100100unsignedLong LongL,r;inttop,top;unsignedLong LongStack[maxn],ans;voidPrework (Long Longx) {    if(x<=r) stack[++top]=x;Else return; Prework (x*Ten+6); Prework (x*Ten+8);}BOOLcmpLong LongALong Longb) {returnA>b;}Long LonggcdLong LongALong Longb) {if(!B)returnAreturnGCD (b,a%b);}voidDFS (intDepintTLong Longx) {    if(dep==top+1)         {            if(t%2) ans+=r/x-(l1)/x; Else if(t) ans-=r/x-(l1)/x; return; } DFS (DEP+1, t,x); if(STACK[DEP]*X/GCD (stack[dep],x) <=R) DFS (DEP+1, t+1, stack[dep]*x/gcd (stack[dep],x));}intMain () {//freopen ("a.in", "R", stdin);//freopen ("A.out", "w", stdout);scanf"%lld%lld",&l,&R); Prework (6); Prework (8); Sort (Stack+1, stack+top+1);//for (int i=1; i<=top; i++) printf ("%d", stack[i]); Puts ("");     for(intI=1; i<=top; i++)         if(Stack[i]) { for(intj=i+1; j<=top; J + +)                    if(stack[j]%stack[i]==0) stack[j]=0; stack[++top]=Stack[i]; } sort (Stack+1, stack+top+1, CMP);//for (int i=1; i<=top; i++) printf ("%d", stack[i]); Puts ("");Daso1,0,1); printf ("%lld\n", ans); return 0;}
BZOJ1853
#include <iostream>#include<cstdio>#include<cmath>#include<cstring>#include<algorithm>using namespacestd;#defineMAXN 10010intL,r,top,top;Long LongStack[maxn],ans;voidPrework (Long Longx) {    if(x<=r) stack[++top]=x;Else return; Prework (x*Ten+2); Prework (x*Ten+9);}BOOLcmpLong LongALong Longb) {returnA>b;}Long LonggcdLong LongALong Longb) {if(!B)returnAreturnGCD (b,a%b);}voidDFS (intDepintTLong Longx) {    if(dep==top+1)         {            if(t%2) ans+=r/x-(l1)/x; Else if(t) ans-=r/x-(l1)/x; return; } DFS (DEP+1, t,x); if(STACK[DEP]*X/GCD (stack[dep],x) <= (Long Long) R) DFS (DEP+1, t+1, stack[dep]*x/gcd (stack[dep],x));}intMain () {scanf ("%d%d",&l,&s); Prework (2); Prework (9); Sort (Stack+1, stack+top+1);//for (int i=1; i<=top; i++) printf ("%d", stack[i]); Puts ("");     for(intI=1; i<=top; i++)         if(Stack[i]) { for(intj=i+1; j<=top; J + +)                    if(stack[j]%stack[i]==0) stack[j]=0; stack[++top]=Stack[i]; } sort (Stack+1, stack+top+1, CMP);//for (int i=1; i<=top; i++) printf ("%d", stack[i]); Puts ("");DFS (1,0,1); printf ("%lld\n", ans); return 0;}

Went to the Codevs group asked the wave. Feeling retarded +10

"bzoj-1853&2393" Lucky number &cirno the perfect arithmetic classroom repulsion principle + burst search + pruning

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.