题目链接:https://vjudge.net/problem/HackerRank-leonardo-and-lucky-numbers 题解: 1.根据扩展欧几里得:7*x + 4*y = gcd(7,4) = 1,必有整数解,其中一组为(-1,2),通解为:(-1+4*k, 2-7*k). 2.当:7*x + 4*y = n,其中一组解为(-n,2*n),通解为:(-n+4*k, 2*n-7*k). 3.若要上式有解,则通解(-n+4*k, 2*n-7*k)中必须至少有一对非负的整数解.…
Description The modular modular multiplicative inverse of an integer a modulo m is an integer x such that a-1≡x (mod m). This is equivalent toax≡1 (mod m). Input There are multiple test cases. The first line of input is an integer T ≍ 2000 indicating…
ztr loves lucky numbers 题目链接: http://acm.hust.edu.cn/vjudge/contest/121332#problem/I Description ztr loves lucky numbers. Everybody knows that positive integers are lucky if their decimal representation doesn't contain digits other than 4 and 7. For…
C. Lucky Numbers time limit per test 0.5 seconds memory limit per test 64 megabytes input standard input output standard output The numbers of all offices in the new building of the Tax Office of IT City will have lucky numbers. Lucky number is a num…
C Looooops DescriptionA Compiler Mystery: We are given a C-language style for loop of type for (variable = A; variable != B; variable += C) statement;I.e., a loop which starts by setting variable to value A and while variable is not equal to B, repea…
题意:很明显,我就不说了 分析:令n=2^k,因为A,B,C<n,所以取模以后不会变化,所以就是求(A+x*C)%n=B 转化一下就是求 C*x=B-A(%n),最小的x 令a=C,b=B-A 原式等于ax=b(mod n) 这就是标准的解模线性方程 该方程有解的充要条件是d=gcd(n,a) && d|b(可以根据这一条判断是否FOREVER) 然后参考算法导论应用扩展欧几里得求解x a*x0+n*y0=d x=x0*(b/d)(mod n) 然后应用多解条件求最小正整数解,即解的…
http://poj.org/problem?id=2115 题意:对于C的循环(for i = A; i != B; i+=C)问在k位存储系统内循环多少次结束: 若循环有限次能结束输出次数,否则输出 FOREVER: 解:设x为循环次数:  (A+C*x)%2^k = B; 则 C*x+A = 2^k*y+B; 所以 C*x - 2^k*y = B-A; 类似于a*x+b*y = c (或 a*x = c(mod b))模线性方程的形式,所以可以根据扩展欧几里得算法解决 #include<s…
Problem Description ztr loves lucky numbers. Everybody knows that positive integers are lucky if their decimal representation doesn't contain digits other than 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Lucky number is…
630C - Lucky Numbers 题目大意: 给定数字位数,且这个数字只能由7和8组成,问有多少种组合的可能性 思路: 假设为1位,只有7和8:两位的时候,除了77,78,87,88之外还哇哦加上前面只有7和8的情况,一共是6位.所以递推式不难写出dp[i]=pow(2,i)+dp[i-1]; 代码: #include <bits/stdc++.h> using namespace std; typedef long long ll; ll ans[56]; void init ()…
题目链接:http://poj.org/problem?id=2115 C Looooops Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 22912   Accepted: 6293 Description A Compiler Mystery: We are given a C-language style for loop of type for (variable = A; variable != B; vari…