栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

poj 2847 The Cubic End

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

poj 2847 The Cubic End

#include "iostream"#include "cstdio"#include "cmath"#include "cstring"using namespace std;typedef unsigned long long ull;const ull mod = 10000000000;char s[12];int re[12];ull cub[12], po[12];int n;ull cal(ull ans, int i, int j){    ull tmp = (3*j*po[i])%po[i+1];    tmp = (((tmp*ans)%po[i+1])*ans)%po[i+1];    ull tp2 = (((ans*ans)%po[i+1])*ans)%po[i+1];    return ((tmp+tp2)/po[i])%10;}bool dfs(int i, ull ans){    if(i >= n) return true;    for(int j = 0; j <= 9; j++)    {        if(cal(ans, i, j) == s[n-1-i]-'0')        { re[n-1-i] = j; if(dfs(i+1, ans+j*po[i])) return true;        }    }    return false;}int main(){    int t;    scanf("%d",&t);    po[0] = 1;    for(int i = 1; i < 12; i++) po[i] = po[i-1]*10;    while(t--)    {        scanf("%s",s);        n = strlen(s);        if(s[n-1] == '3') re[n-1] = 7;        else if(s[n-1] == '7') re[n-1] = 3;        else re[n-1] = s[n-1]-'0';        dfs(1, re[n-1]);        int i = 0;        while(re[i] == 0) i++;        while(i < n)        { printf("%d",re[i]); i++;        }        printf("n");    }    return 0;}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/366880.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号