codeforce 460B Little Dima and Equation

这道题给出了一个犀利的公式x=b·s(x)a+c,
s(x)为求x的各个位数之和,求在0-1000000000之间找到满足这个公式值,明显暴力枚举绝对超时,遍历一边都得一分钟的时间,所以就要分析公式

可以看出s(x)^a=(x-c)/b,也就是说(x-c)/b一定是一个整数,所以循环可以写成for(int i=c;i<1000000000;i+=b),但这个优化远远不够

的以上思路都是遍历x的值,仔细看公式,里面有一个s(x)^a,说明一个问题,就是可以遍历s(x),这样遍历的范围缩减为0-85,为什么呢,最大值999999999的各个位之和就是81,所以for(int i=1;i<85;i++)遍历s(x),再通过x=s(x)^a*b+c的到x,再看x的各个位之和是否=i,这里s(x)^a*b+c注意这个值会超过int,所以的用long
long ,比赛的时候我就wa在这里的,还有就是pow函数在codeforce不好使,交上去就wa,也让我wa了两次,jiong

#include<iostream>
#include<stdio.h>
#include<math.h>
using namespace std;
int tsum(int i){
    int sum=0;
    while(i){
        sum+=(i%10);
        i/=10;
    }
    return sum;
}
long long powd(int t,int n){
    long long sum=1;
    for(int i=1;i<=n;i++)
        sum*=t;
    return sum;
}
int main(){
    int a,b,c;
    while(~scanf("%d%d%d",&a,&b,&c)){
        int cou=0;
        int aa[100000];
        for(int i=1;i<85;i++){
            long long t=powd(i,a);
            long long x=t*b+c;
            if(x>0 && x<1000000000 && tsum(x)==i){
                aa[cou++]=x;
            }
        }
        printf("%d\n",cou);
        for(int i=0;i<cou;i++){
            if(i==(cou-1))
                printf("%d\n",aa[i]);
            else
                printf("%d ",aa[i]);
        }
    }
}

codeforce 460B Little Dima and Equation

时间: 2024-10-08 10:52:34

codeforce 460B Little Dima and Equation的相关文章

Codeforces Round #262 (Div. 2) 460B. Little Dima and Equation(枚举)

题目链接:http://codeforces.com/problemset/problem/460/B B. Little Dima and Equation time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Little Dima misbehaved during a math lesson a lot and the nas

Little Dima and Equation

Little Dima misbehaved during a math lesson a lot and the nasty teacher Mr. Pickles gave him the following problem as a punishment. Find all integer solutions x (0?<?x?<?109) of the equation: x?=?b·s(x)a?+?c,? where a, b, c are some predetermined co

Codeforces Round #262 (Div. 2) (460A 460B 460C 460D)

460A Vasya and Socks 题意:n个物品每天用一个  m天得一个  问  最多连续用几天 思路: 没思路-  就是暴力- 代码: #include<cstdio> #include<iostream> #include<string> #include<cstring> #include<algorithm> #include<cmath> #include<map> #include<set>

CodeForces 460B

Little Dima and Equation Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit Status Practice CodeForces 460B Description Little Dima misbehaved during a math lesson a lot and the nasty teacher Mr. Pickles gave him the

Codeforces Round #262 (Div. 2) 总结:二分

B. Little Dima and Equation 思路:本来前两题都很快做出来的,然后觉得ranting应该可以增加了.然后觉得代码没问题了,又想到了一组cha人的数据,然后就锁了,然后刚锁就被别人cha了看了代码才发现尼玛忘了判断小于10^9了,然后C反正想了好多种方法都不会就没心情了,就这样rating又降了 #pragma comment(linker, "/STACK:1024000000,1024000000") #include<iostream> #in

Codeforces Round #262 (Div. 2) 题解

A. Vasya and Socks time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Vasya has n pairs of socks. In the morning of each day Vasya has to put on a pair of socks before he goes to school. When

大神刷题表

9月27日 后缀数组:[wikioi3160]最长公共子串 dp:NOIP2001统计单词个数 后缀自动机:[spoj1812]Longest Common Substring II [wikioi3160]最长公共子串 [spoj7258]Lexicographical Substring Search 扫描线+set:[poj2932]Coneology 扫描线+set+树上删边游戏:[FJOI2013]圆形游戏 结论:[bzoj3706][FJ2014集训]反色刷 最小环:[poj1734

Codeforces Round #262 (Div. 2) B

题目: B. Little Dima and Equation time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Little Dima misbehaved during a math lesson a lot and the nasty teacher Mr. Pickles gave him the following pr

Codeforces Round #262 (Div. 2)-A,B,C,D

A. Vasya and Socks 水题就不用多说了,直接暴力枚举就完事了. #include <iostream> #include<stdio.h> #include<stdlib.h> #include<time.h> #include<vector> #include<algorithm> #include<string.h> using namespace std; #define LL __int64 int