代码:递归搜索一下。java大数做法

import java.util.*;
import java.math.*;
import java.security.MessageDigest; public class Main {
static BigInteger s=BigInteger.ONE.add(BigInteger.ONE);
public static void main(String[] args) {
Scanner cin=new Scanner(System.in);
int T;
T=cin.nextInt();
while(T-->)
{
BigInteger a,b,n; n=cin.nextBigInteger();
a=cin.nextBigInteger();
b=cin.nextBigInteger();
BigInteger ans=cul(n,a,b).mod(BigInteger.valueOf());
System.out.println(ans); }
}
public static BigInteger cul(BigInteger n,BigInteger a,BigInteger b)
{
if(n.equals(BigInteger.ONE))
{
BigInteger sum1=n.multiply(n).multiply(n).multiply(b).add(n.subtract(BigInteger.ONE).multiply(n).multiply(n).multiply(a));
return sum1;
}
return min((n.divide(s)).multiply(n.divide(s)).multiply(BigInteger.valueOf()).multiply(a).add(cul(n.divide(s),a,b).multiply(BigInteger.valueOf())),n.multiply(n).multiply(n).multiply(b).add(n.subtract(BigInteger.ONE).multiply(n).multiply(n).multiply(a)));
}
private static BigInteger min(BigInteger add, BigInteger add2) {
// TODO Auto-generated method stub
if(add.compareTo(add2)<)
return add;
else return add2;
}
}

C++:

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<queue>
#include<set>
#include<cmath>
#include<string>
#include<map>
#include<vector>
#include<ctime>
#include<stack>
using namespace std;
#define mm(a,b) memset(a,b,sizeof(a))
typedef long long ll;
const long long mod = 1e9 + ;
const int maxn = 1e5 + ;
const ll inf = 1e18;
ll a, b;
ll f1(ll n) {
n %= mod;
return (n*n%mod*n%mod*b%mod + n * n%mod*(n - ) % mod*a%mod) % mod;
}
ll f2(ll n) {
if (n % ) return f1(n);
if (n <= * a / (a + b)) return f1(n);
return ( * (n / ) % mod*(n / ) % mod*a%mod + * f2(n / ) % mod) % mod;
}
int main()
{
int t;
ll n;
cin >> t;
while (t--)
{
scanf("%lld%lld%lld", &n, &a, &b);
printf("%lld\n", f2(n));
}
}

【百度之星】【java大数+C++做法】hdu 6719 Strassen的更多相关文章

  1. 2017"百度之星"程序设计大赛 - 复赛1001&&HDU 6144 Arithmetic of Bomb【java大模拟】

    Arithmetic of Bomb Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Other ...

  2. 2017"百度之星"程序设计大赛 - 复赛1005&&HDU 6148 Valley Numer【数位dp】

    Valley Numer Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tota ...

  3. 2017"百度之星"程序设计大赛 - 复赛1003&&HDU 6146 Pokémon GO【数学,递推,dp】

    Pokémon GO Time Limit: 3000/1500 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  4. JAVA大数几算--HDU 2054 A == B ?

    Problem Description Give you two numbers A and B, if A is equal to B, you should print "YES&quo ...

  5. 【百度之星】【思维】hdu 6724Totori's Switching Game

    思维题,最后只要判断每个点的度数>=k即可. #pragma comment(linker, "/STACK:1024000000,1024000000") #pragma ...

  6. HDU 5686:2016"百度之星" - 资格赛 Problem B

    原文链接:https://www.dreamwings.cn/hdu5686/2645.html Problem B Time Limit: 2000/1000 MS (Java/Others)    ...

  7. HDU 6118 度度熊的交易计划 【最小费用最大流】 (2017"百度之星"程序设计大赛 - 初赛(B))

    度度熊的交易计划 Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total S ...

  8. HDU 6119 小小粉丝度度熊 【预处理+尺取法】(2017"百度之星"程序设计大赛 - 初赛(B))

    小小粉丝度度熊 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Sub ...

  9. HDU 6114 Chess 【组合数】(2017"百度之星"程序设计大赛 - 初赛(B))

    Chess Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submi ...

随机推荐

  1. C#async/await心得

    结论: 异步方法的方法签名要加 async,否则就算返回 Task 也是普通方法. 调用异步方法,可以加 await 或不加 await,两者方式都是马上返回,不加 await 得到的是 Task 对 ...

  2. 【eclipse】No enclosing instance of type A is accessible. Must qualify the allocation with an enclosing instance of type A

    用 eclipse 写 Java 代码时出现了这个问题,详细如下: No enclosing instance of type TestParsingLinkedList is accessible. ...

  3. Python中的inf与nan

    Python中可以用如下方式表示正负无穷 >>> float('inf') # 正无穷,inf不区分大小写,float('InF')一样可以. inf >>> fl ...

  4. 【Python-django后端开发】logging日制配置详解!!!

    官方文档请查看:https://docs.djangoproject.com/en/1.11/topics/logging/ 1. 配置工程日志,在setting.py里,如下 LOGGING = { ...

  5. oracle常用的一些sql命令

    //查看系统当前时间   HH24 24小时制  MI是正确的分钟 select to_char(sysdate,'yyyy-mm-dd HH24:MI:SS') from dual //HH非24 ...

  6. C# Winform 自定义控件——TextBox

    效果:   描述: 类似html标签里input标签里的placeHolder属性,控件继承TextBox,拥有一个描述提示信息的字段_txtPlaceHolder,重写了消息处理函数WndProc, ...

  7. .net core 基于 IHostedService 实现定时任务

    .net core 基于 IHostedService 实现定时任务 Intro 从 .net core 2.0 开始,开始引入 IHostedService,可以通过 IHostedService ...

  8. ECharts图表插件(4.x版本)使用(一、关系图force节点显示为自定义图像/图片,带分类选择)

    导读 ECharts,一个使用 JavaScript 实现的开源可视化库,可以流畅的运行在 PC 和移动设备上,兼容当前绝大部分浏览器(IE8/9/10/11,Chrome,Firefox,Safar ...

  9. 8、JAVA中的用户输入(I/0交互过程)

    这里在数组的学习中用到了用户输入,也就是交互模式,日常的数据,不可能每一次都是程序员定义好的,终究需要用户与程序之间进行交互,机器等待用户输入,用户通过键盘输入所需数据(数据包括,字符,字串,数值等) ...

  10. kafka同步异步消费和消息的偏移量(四)

    1. 消费者位置(consumer position) 因为kafka服务端不保存消息的状态,所以消费端需要自己去做很多事情.我们每次调用poll()方法他总是返回已经保存在生产者队列中还未被消费者消 ...